Answer the question
In order to leave comments, you need to log in
How to correctly set scopes() with with() in relation to MANY_MANY in Yii1?
Good afternoon,
There are 3 tables - m_users , m_firms and l_users_22_firms (connective)
Links in l_users_22_firms are not repeated.
In the Users model, I want to make a selection condition for all users belonging to a conditional company.
I tried this:
public function relations()
{
return
[
'firm' => [self::MANY_MANY, 'Firms', 'l_users_22_firms(id_1, id_2)'],
...
];
}
public function scopes()
{
return array_merge
(
parent::scopes(),
[
'owner' =>
[
'with'=>
[
'firm' =>
[
'condition' => 'firm_id='.Firms::getFirmID()
]
]
],
]
);
}
$customers = Users::model()->owner()->findAll();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question