Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
yii relations可从多个表创建关系_Yii_Relationship - Fatal编程技术网

yii relations可从多个表创建关系

yii relations可从多个表创建关系,yii,relationship,Yii,Relationship,我有三张桌子 交易:-id,companyId,COMPANY:-id,userId,姓名,网站,地址 用户:-id、电子邮件、密码、 我想要公司的电子邮件id。哪个在用户表中 目前我正在做交易 那么在交易模式中,我应该建立什么关系 提前感谢。只需将公司关系添加到您的交易中,您就可以将这些内容链接在一起: 交易中: 'company' => [self::BELONGS_TO, 'Company', 'companyId'] 'company' => [self::BELONGS_

我有三张桌子

交易:-id,companyId,COMPANY:-id,userId,姓名,网站,地址 用户:-id、电子邮件、密码、

我想要公司的电子邮件id。哪个在用户表中

目前我正在做交易

那么在交易模式中,我应该建立什么关系


提前感谢。

只需将公司关系添加到您的交易中,您就可以将这些内容链接在一起:

交易中:

'company' => [self::BELONGS_TO, 'Company', 'companyId']
'company' => [self::BELONGS_TO, 'Company', 'companyId'],
'user' => [self::BELONGS_TO, 'User', 'userId', 'through' => 'company']
公司:

'user' => [self::BELONGS_TO, 'User', 'userId']
'user' => [self::BELONGS_TO, 'User', 'userId']
然后,您可以执行
$deal->company->user->email

作为的扩展,您可以使用以下方法访问没有父关系的子关系,即减少链接

公司:

'user' => [self::BELONGS_TO, 'User', 'userId']
'user' => [self::BELONGS_TO, 'User', 'userId']
交易中:

'company' => [self::BELONGS_TO, 'Company', 'companyId']
'company' => [self::BELONGS_TO, 'Company', 'companyId'],
'user' => [self::BELONGS_TO, 'User', 'userId', 'through' => 'company']
然后你可以做
$deal->user->email