0

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.

mtwell
  • 33
  • 6

1 Answers1

1
'contain' => array(
        'Country',
        'ArrivalDate',
        'ArrivalDate.Salesman' => array( insert needed fields here ... )
    )

should work in your case

arilia
  • 9,373
  • 2
  • 20
  • 44
  • Thank you, very simple. I discovered that the problem I had was complicated by a virtual field in the Person model. – mtwell Oct 03 '13 at 22:54