0

Here's my issue, and my tables:

**sales_person**
id | sp_number | name
31 | 23948223  | John Doe

**Team**
id  |    name    | parent_id | lft | rght
52  | Super Team |     1     |  1  |  2

**Team_Salesmen**
id | team_id | sales_person_id
1  |    52   |      31

So I have my sales people, my teams, and a table to show which salespeople belong to which teams.

I was going to display a list of all of a team's children teams, then list all of their salespeople.

Teams is related to Team_salesmen by the team_id, so I can do a contain on that. The trouble is, this only returns the Team_salesmen entity 'id:1, team_id:52, sales_person_id:31', whereas I need it to return the name and number of the salesman.

So, while in the Teams model I need to contain with TeamSalesmen and then contain from TeamSalesmen to SalesPerson. How can I chain commands? CakePHP thinks I'm trying to contain Teams to SalesPersons, which aren't related directly.

Isaac Askew
  • 1,281
  • 2
  • 17
  • 30

1 Answers1

1

Well...I feel stupid now. I was browsing the old CakePHP posts on this and found this link.

So I just tried:

->contain(['TeamSalesmen' => ['SalesPerson']])

Just for kicks, and it worked. facepalm

Awesome!

Community
  • 1
  • 1
Isaac Askew
  • 1,281
  • 2
  • 17
  • 30
  • It's also explained in detail [**in the cookbook**](http://book.cakephp.org/3.0/en/orm/query-builder.html#loading-associations). – ndm Jan 23 '15 at 13:12