我有两个eloquent型号:
class User extends Eloquent
{
public function phone()
{
return $this->hasOne('App\Models\Phone');
}
public function phones()
{
return $this->hasMany('App\Models\Phone');
}
}
class Phone extends Eloquent
{
public function user()
{
return $this->belongsTo('App\Models\User');
}
}
如果User::first()->phone()->toSql()
和User::first()->phone()->toSql()
生成相同的原始sql查询:
select * from `phones` where `phones`.`user` = ? and `phones`.`user` is not null
hasOne
和hasMany
关系有什么区别?