我在 MySQL 数据库中有以下表结构:
Products
id - integer
name - string
user_id -string
Users
user_id - string
password - string
person_id - integer
Persons
person_id - integer
name - string
email - integer
我正在使用hasOneThrough
Products 模型上的关系来获取有关Person
链接的详细信息Users
。定义关系的代码如下:
public function product_user()
{
return $this->hasOneThrough(
'App\Person',
'App\User',
'person_id',
'person_id',
'user_id',
'user_id'
);
}
但是null
当我尝试访问该属性product_user
时,它一直在给我null
。我无法更改数据库结构。在这种情况下如何定义正确的关系?