$sql = Db::connect('数据库')->table('C表')->where('status', 'normal')->field('字段 别称【不可与其他表重复】')->buildSql();
$total = $this->model
                    ->fetchSql(false)
                    ->with(['B表'])
                    ->join([$sql=>'C表'],'C表关联B表字段 = B表关联C表字段','left')
                    ->where($where)
                    ->order($sort, $order)
                    ->count();

上面是自己想的,后来发现了下面这种方法更简单

->with(['B模型'=>['C方法']])
foreach ($list as $row) { 
  $row->visible(['B模型']);
$row->getRelation('B模型')->visible(['C方法']);
$row->seller = ['C字段'=>$row->B模型->C方法->C字段];
}

 

相关文章:

  • 2022-12-23
  • 2021-07-23
  • 2021-08-13
  • 2021-06-12
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-29
  • 2021-09-16
  • 2021-11-30
  • 2021-05-10
相关资源
相似解决方案