Monday, February 18, 2013

Re: Model relations (optional level)

How about setting up the companies table as a tree, where subsidiaries are beneath their company in the tree. Then a user can simply acquire the 'company_id' which could be either a company or a subsidiary.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 18 Feb 2013, at 19:40:45, Yvon <ruthox@gmail.com> wrote:

It probably depends why you need this information?  Is the subsidiaries "financial" is unique for company A ?  Or it can be assigned to company A, B and C ?

I mean, would it be

C-A  S-1
C-A  S-2
C-A  S-3
C-B  NULL
C-C  S-4
C-C  S-5 
etc..

or

C-A  S-1
C-A  S-2
C-A  S-3
C-B  NULL
C-C  S-1
C-C  S-2
C-D  S-2
??

I guess it would have to be the 2nd choice..    And if it's the 2nd choice, your user table needs the cie_id (not NULL) and the sub_id which can be NULL.. (or blank)

If it's the 1st option (because you would need the S-id for an employee for the informations on the pay as example), well..  You will only need the id, with one table containing parent_id, id, name where the parent_id will be the company id... with a NULL if its the company.  (Or you can have sub_subsidiaries..

example :

C-A S-1 Room-1
             Room-2
C-A S-2
C-B
B-C S-3
etc..

It's not the easiest on an email.. but well..  Does it make sense?


C


On Monday, February 18, 2013 1:34:31 PM UTC-5, LDSign wrote:
Hi

I am not sure how to give this thread a clear title or topic. But let me explain what I am trying to do (or find the best and "right" practice for this approch).

Think of 3 tables: Users, companies and subsidiaries. Users always belong to a company but they could (!) belong to subsidiary which is itself related to a company.

So there are 2 constellations:

Company -> Users

Company -> Subsidiaries -> Users

The relation between a company and a subsidiary is clear. But what is the best approach for storing the user relation?

Set both company_id + subsidiary_id in the user model although subsidiary_id has already a relation to a company? This could lead into illogical data, if the relation between company and subsidiary has changed.

Or leaving company_id empty in that case and only setting the subsidiary_id? In the other case leave subsidiary_id empty if a user belongs directly to a company.

What do you think?

Thanks,
Frank

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: