Sunday, May 2, 2010

The docs for Containable does not work for complex search. Complex search is 2 models away. For cake 1.3

Hi,

i have the following for my cake 1.3:

User hasOne Merchant (so Merchant belongsTo User)
Shop hasMany Merchant (so Merchant belongsTo Shop as well.)
Shop hasMany Domain (so Domain belongsTo Shop.)

i need to use Merchant model to do a find of all 4 related data.
notice that Domain is the only one NOT directly related to Merchant.

i tried this in a method inside Merchant model:

$this->Behaviors->attach('Containable');
$this->User->Behaviors->attach('Containable');
$this->Shop->Behaviors->attach('Containable');
$this->Shop->Domain->Behaviors->attach('Containable');

$this->recursive = -1;
$this->User->recursive = -1;
$this->Shop->recursive = -1;
$this->Shop->Domain->recursive = -1;

return $this->find('first',
array(
'contain'=>array(
'User',
'Shop' => array('Domain' ),

),
'conditions' => $conditions
));

http://book.cakephp.org/view/1323/Containable has errors in terms of
telling you where to place the conditions. my way is correct as of 1.3
Cakephp

but there is no way to get the Domain.

I also noticed that the doc told us about using fields.

it is so vague i am not even sure what fields to put inside. they
mentioned that foreign keys but do the example like id, name, note
look like foreign key? they look like primary key and field .

another thing is it is not consistent. look at AccountSummary and
compare it with PostAttachment.

both are 2 models away from main model but AccountSummary does not
need to use fields, i wonder why PostAttachment needs it?

anyway if you have problems with complicated search, like mine, use
joins. more reliable than Containable see http://book.cakephp.org/view/1047/Joining-tables

please advise me on how to use Containable so i can use it instead of
custom queries.

Thank you

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

No comments: