> I'm confused on when to rely on correctly configured associations, when
> to add an additional bindModel, and when to do something like:
>
> $result = $this->A->B->C->FindAll();
This does not do anything special -- if you controller had
var $uses = array('C');
Then doing
$this->A->B->C->findAll()
is equivalent to doing
$this->C->findAll()
Internally, Cake only keeps one copy of each Model -- so the object
referenced by $this->A->B->C is the same one that is referenced by
$this->C
> To my simple mind, if I've configured the associations correctly, and
> have set recursive parameter to 2 in the $this->A->findAll(), I
> shouldn't need extra steps to get model C to be included. Where am I
> mistaken?
I suggest you set up debug to 2 or 3 in app/config/core.php -- this
will show you the SQL that gets executed, so you will be able to
understand what it happening.
You've set up the associations, so findAll will return the associated
data. hasOne and belongsTo associations are returned using the same SQL
statement. However hasMany associations are queried using a separate
SQL statement -- so the condition in 'findAll' will not apply to those
tables.
You can, however, set up the condition for that extra SQL statement
(the one that queries the hasMany associated records) when you define
the hasMany association :
class A extends AppModel
{
var $name = 'A';
var $hasMany = array(
'B' => array(
'className' => 'B',
'conditions' => 'A.field1 = B.field2'
)
);
}
If your condition is not permanent, you can use bindModel/unbindModel
(see http://manual.cakephp.org/chapter/models) to set/unset them on the
fly.
If you want to use 'group by' then you should use bindModel to set up
the association as a hasOne association -- see this thread for more
details :
http://groups-beta.google.com/group/cake-php/browse_thread/thread/e35fe10fdefbb1db/6c08d567416cfbea
Anselm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---