profile表 字段id,user_id,email,sex
创建了User模型
创建了Profile模型其中定义了
public function user()
{
return $this->belongsTo('User','user_id');
}
需求:想通过关联查询查询user.username=小明 and profile.sex=男 的用户
请问用模型怎么查询呢?
我现在是用view视图查询
Db::view('profile p')->view('user u','username,password','u.id=p.user_id')->where(['u.username'=>'小明','p.sex'='男'])->select();
最佳答案
