E
E
EVOSandru62016-02-18 12:19:12
Yii
EVOSandru6, 2016-02-18 12:19:12

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()
                        ]
                    ]
                ],
            ]
        );
    }

At the same time, the filtering does not work (And all users are output:
$customers = Users::model()->owner()->findAll();
Where did I mess up?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EVOSandru6, 2016-02-18
@EVOSandru6

Got it, syntax error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question