Tuesday, November 29, 2011

Conditions in model associations

I've noticed that if I have conditions on model associations, for
example:

$hasMany = array(
'ActiveUser' => array(
'className' => 'User',
'foreignKey' => 'group_id',
'conditions' => array(
'ActiveUser.active' => 1
)
)
);

...and bring that key into a find BUT with an added condition, for
example;

$groups = $this->find(
'all',
array(
'contain' => array(
'ActiveUser' => array(
'conditions' => array(
'ActiveUser.id' => 10
)
)
)
)
);

...the condition on the join is ignored. So in this example the user
with an id of 10 will come back whether he is active or not.

How do I overcome that?

--
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: