tp5一对多,a表hasmany b表,b表hasmany c表

 1 // 在a model定义b model关联
 2 public function hasManyB()
 3 {
 4     return $this->hasMany('关联模型b的模型名');
 5 }
 6 // 在b model定义c model关联
 7 public function hasManyC()
 8 {
 9 return $this->hasMany('关联模型c的模型名');
10 }
11 // 在a model中执行查询
12 $result = $this->with(['hasManyB' => ['hasManyC']])->where($where)->order($order)->select();

 

  1. // 在a model定义b model关联
  2. public function hasManyB()
  3. {
  4.     return $this->hasMany('关联模型b的模型名');
  5. }
  6. // 在b model定义c model关联
  7. public function hasManyC()
  8. {
  9. return $this->hasMany('关联模型c的模型名');
  10. }
  11. // 在a model中执行查询
  12. $result = $this->with(['hasManyB' => ['hasManyC']])->where($where)->order($order)->select();
posted @ 2020-11-08 00:18  九鹤  阅读(1305)  评论(0编辑  收藏  举报