Thursday, October 1, 2009

Re: find() when having nested models

Yes, I read that too, and later in the text is this note:

"When using 'fields' and 'contain' options - be careful to include all
foreign keys that your query directly or indirectly requires."

And to me it looks like you should ensure that you specify the primary
keys (id) and the foreign keys (c_id, etc) in order for it to work!

A quick test is just to not specify any fields and see if Containable
works then!
Enjoy,
John

On Oct 1, 3:01 pm, Melanie Sommer <melanie-som...@mailinator.com>
wrote:
> Hi John,> I think I read somewhere (here in the group) that you need to include
> > the foreign keys in the fields definition, so containable can see
> > them!
>
> I read contain automatically also includes the foreign keys in it's
> sql-query.
>
> http://book.cakephp.org/view/474/Containable:
> "As you can see, the Comment arrays only contain the author field
> (plus the post_id which is needed by CakePHP to map the results)."
>
> CakePHP does this - but strangely it does not inlcude C.A_id. All
> other foreign keys are included.
> I just checked if the hasMany and belongsTo relations in my models are
> correct:
> C HasMany(array(A,B));
> C belongsTo(D);
>
> even if I include C.A_id in the "fields"-option the "where A.id =
> C.id" stays wrong.
>
> Any more ideas?
> Melanie
--~--~---------~--~----~------------~-------~--~----~
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: