I searched quite some for this, but I don't even know what to call it.
In a simplified version, I have these Models:
Person
(id, name) - hasMany: ArrivalDate
Country
(id, name) - hasMany: Person
ArrivalDate
(id, arrival_date, salesman_id) - belongsTo: Person
, Salesman
(className => Person
)As you can see, I'm trying to have the people with arrival dates and the salesmen in ONE TABLE.
Upon retrieving the data I use the containable behavior to get only the models I want.
$person = $this->Person->find('first', array(
'conditions' => array('Person.id' => $id),
'contain' => array(
'Country',
'ArrivalDate'
)
));
But the question is: How do I "contain" the Salesman
in this?
Salesman
is just an alias for the Person
and if I contain the Person
model I just get the parent data. If I try to contain the alias (Salesman
) I get an error.
'contain' => array(
'Country',
'ArrivalDate',
'ArrivalDate.Salesman' => array( insert needed fields here ... )
)
should work in your case