> On Wed, Oct 27, 2010 at 8:07 AM, Dan <dannyetdi...@gmail.com> wrote:
> > Structure:
>
> > Projects
> > - project_id
> > - project_name
>
> > Contacts
> > - contact_id
> > - contact_name
>
> > Contacts_Projects
> > - project_id
> > - contact_id
>
> > When reading the Cookbook, in a HABTM setting, I should add an ID
> > field to the Contacts_Projects table.
>
> That's not a requirement. But, if you find that you need to store
> extra information in the join table, it's recommended that you then
> add a primary key.
>
> > Wouldn't this field enable the
> > possibility of having duplicates?
>
> UNIQUE(project_id, contact_id);
>
> This creates an index. That's why a PK isn't absolutely necessary.
>
> > Or does the ID field only act as auto number, but the key is still
> > composed of project_id/contact_id?
>
> Sort of. The id column becomes the PK and you'd then have two indexes
> on the table. If you do add a PK, you should keep the unique index as
> that's what Cake will be using. However, Cake doesn't ever use
> multi-column PKs..
Okay, so if my linking table has a PK comprised of these two fields
(and no ID auto number field) should I remove the primary key and
replace it with an index?
My goal is to simply associate contacts to a project, thus each
model's PK. I don't need the ID field in that case right?
> that's what Cake will be using. However, Cake doesn't ever use
> multi-column PKs..
I always thought that having a multi-column PK was "standard" when
developing a DB?
Next, putting those associations to work :)
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment