into a cake-like array for you. As such you cannot throw in
conditions on deeply associated models and expect it to limit the
results. You need to force joins so you can specify the conditions
you want.
To limit the amount of ad-hoc joins you will have to make I would run
this find on the Bill model as that is directly related to Account and
BillResource. However, we need to change the Bill hasMany
BillResource to Bill hasOne BillResource, so it runs one query using
all 3 tables, using unbindModel and bindModel.
If running this from the Client controller, add the following to the
relevant action:
$this->Client->Account->Bill-
>unbindModel(array('hasMany'=>array('BillResource')));
$this->Client->Account->Bill-
>bindModel(array('hasOne'=>array('BillResource')));
$this->Client->Account->Bill->find('all', array(
'conditions'=>array(
'Account.client_id'=>$client_id,
'BillResource.resource_type_id'=>$resource_type_id
),
'contain'=>array(
'Account'=>array('Client'),
'BillResource'=>array('ResourceType')
)
));
If paginating this data add a false parameter to the unbind and bind
calls as follows (makes the change last the whole http request rather
than just one find call):
$this->Client->Account->Bill-
>unbindModel(array('hasMany'=>array('BillResource')), false);
$this->Client->Account->Bill-
>bindModel(array('hasOne'=>array('BillResource')), false);
I have not tested any of this, so apologies for any typos!
HTH
Paul
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
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
To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
No comments:
Post a Comment