T
T
terkin2015-07-23 20:57:49
Yii
terkin, 2015-07-23 20:57:49

How to make nested relations with condition in yii2?

Maybe I didn't formulate my question correctly, but I need help modifying the request

$request = Request::find()->with('threads.dialogs.company')->asArray()->where(['id' => 1])->one();
        return $request;

I need to add a condition to threads, i.e. add threads.author = 1 but add it directly to the join, so that if there are no records in threads with author = 1, then I still return data from the request table

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ar7n, 2015-07-30
@ar7n

$request = Request::find()->with([
    'threads' => function ($query) {
        $query->andWhere('threads.author = 1');
    },
    'threads.dialogs.company'
])->asArray()->one();
return $request;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question