开发者

CakePHP model associations via an intermediary table?

开发者 https://www.devze.com 2023-01-25 03:59 出处:网络
开发者_如何学GoI have a Home model that links to a Realtor model on Home.realtor_num = Realtor.num.
开发者_如何学Go

I have a Home model that links to a Realtor model on Home.realtor_num = Realtor.num. I have an Office model linked to the Realtor model on Realtor.office_num = Office.num.

Suppose I want easy access to Office.name in the result set of a find on the Homes table. Is there an easy way to specify the above relationship, such that $home['Office']['name'] will contain the data I'm looking for?


If you have correctly setup associations in you models:

  1. you can use containable behavior,
  2. you can access Office model from HomeController: $this->Home->Realtor->Office->find(...)
0

精彩评论

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