开发者

Cakephp: Correct way to resolve hasMany - hasMany relation

开发者 https://www.devze.com 2023-02-01 04:27 出处:网络
I have three models: Company, Car, Passenger Company hasMany Cars Car hasMany Passenger These relations seem to work independetly: Car shows all Passengers and Company shows all Cars.

I have three models:

Company, Car, Passenger

Company hasMany Cars

Car hasMany Passenger

These relations seem to work independetly: Car shows all Passengers and Company shows all Cars.

But I cannot resolve the Company - Passenger (开发者_如何转开发Show all Passengers of a Company).

My controller for Company:

   function index(){
      //grab all companies and pass it to the view:
      $companies = $this->Company->find('all');
      $this->set('companies', $companies);
   }

This displays all companies with all their respective cars. However the array does not contain an entry for passenger.

What do I have to do to completely resovle the Company - Car - Passenger relation?


This should work (if doesn't, check your belongsTo & hasMany relationships)

$this->Company->recursive = 2;
$companies = $this->Company->find('all');
0

精彩评论

暂无评论...
验证码 换一张
取 消