Sunday, March 29, 2009

Re: How to get records for a model based on it's id existing in a linking table?

Cake should be doing that for you anyway. Have you tried getting your
data through the Collection model? Should be:

$data = $this->Collection->find('first', array('conditions' => array
('Collection.id' => $id)));

Where $id is 15, or any other id number. That should find all the
recipients associated with the requested Collection record.
In your result set, you would access all the returned recipients like
normal, ie. $data['Recipient'][...];

On Mar 29, 5:11 pm, Drinkspiller <drinkSpil...@gmail.com> wrote:
> I have two models, Collection and Recipient that have a HABTM
> relationship. The database has a collections_recipients liking table.
>
> Using a specific collection_id, how do I do a find() that gets all
> Recipients that are associated with the collection_id in the linking
> table? I want the end SQL to look like thishttp://bin.cakephp.org/view/2145898894
> (where I supply the id of 15 as the value of the collection_id
> variable)
--~--~---------~--~----~------------~-------~--~----~
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: