User 与 UserProfile 我在User中加了一对一关联: public function profile()
{
return $this->hasOne('UserProfile', 'id', 'id');
}我要使用关联查询官方的例子:
User::with('profile')->select([1,2,3]);但是我需要加入条件查询:User::with('profile')->where(['create_time'=>18311225421])->select();这种就报错了:SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'create_time' in where clause is ambiguous原因是两个表里都有 create_time 字段,我传入条件的时候没有指明,但是框架底层不会自动判断?问题:我写的方式不对,还是关联预载入就不支持条件查询?
最佳答案