Tuesday, February 28, 2012

Re: Filter on a deep model association

Go 3 levels deep so the data is arranged by the particular Collection
you're after.

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

Because the Book model has the collection_id you really only need to
go 2 models deep.

$data = $this->Author->Book->find(
'all',
array(
'conditions' => array(
'Book.collection_id' = $c_id
),
'contain' => array(
'Collection',
'Author'
)
)
);

But then the data will be arranged badly. Collection, for instance,
will be repeated for each Book.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

No comments: