个人对with的用法,请大神帮忙看看
public function user()
{
return $this->hasOne(TestsCopy::class, 'tests_id', 'id')->select(['tests_id']);
}
public static function testWith(){
$a = self::with(['user'])->select(['id','name'])->get()->toArray();
}
一直没理解lavavel除了db类的left join 连表的方式以外还有什么其他方法,今天试了一下模型之间单个连表查询,打印的sql为
select `tests_id` from `tests_copy` where `tests_copy`.`tests_id` in (1, 2, 3) and `tests_copy`.`deleted_at` is null
最后给个人的感觉就是先把主表的数据查询出来后带入带附属表的in查询里面,如果理解不对的地方,还请各位大神指教
推荐文章: