On Feb 7, 5:11 am, WebbedIT <[email protected]> wrote:
> Not sure why mscdex advises removing the id field from the join table,
> I include one in all my join tables without issue, but happy for
> mscdex to elaborate and inform us of some performance improvement that
> may cause :)

If you are solely using the 'id' attribute as your primary key in the
join table, then you are opening up the possibility of allowing a user
to be associated with the same event multiple times. If you remove the
'id' attribute and make both the 'user_id' and 'event_id' as primary
keys (making a composite key), then you are ensuring that a user
cannot belong to the same event many times. IIRC setting the
foreignKey and associationForeignKey to both be primary keys can be
accomplished by having the 'unique' setting be set to true in your
model's HABTM definition.

You still are able to HABTM just fine either way, but making the
changes I suggested prevents the aforementioned problem from
happening.

On Feb 7, 9:29 am, WebbedIT <[email protected]> wrote:
> ... seems I got things slightly
> wrong as I forgot that Cake only joins hasOne and belgonsTo
> associations by default and as such you cant run a $this->Event->find
> () call with a condition from the EventsUsers join table.

CakePHP automatically joins two tables defined by a HABTM relationship
and doesn't create a model to represent this. All you should have to
do is ensure the relationship settings are defined correctly in the
model and that the recursive level is set appropriately. Once you do
this, you should simply be able to use the other model in your find
conditions as I mentioned in the find example in my previous post.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to