A
A
alex995052018-08-08 18:20:12
Yii
alex99505, 2018-08-08 18:20:12

How to pass parameter between links?

In I have a link QuestionUsers
'q_comp' => array(self::HAS_ONE, 'Questions', array('event_id'=>'event_id'), 'on' => 'q_comp.link_company=1'),
In Questions there is a relationship
'q_ans_comp' => array(self::HAS_ONE, 'QuestionAnswers', array('event_id'=>'event_id','question_id'=>'id'))
You need to reach QuestionAnswers, but also pass the id with QuestionUsers (in fact, you need the condition QuestionUsers .id = QuestionAnswers.user_id):
$data->q_comp->q_ans_comp->answer

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Belka2007, 2018-08-16
@Belka2007

The parameter can be passed using an anonymous function when requested.

Question::find()->with([
    'answers' => function ($query) use ($user_id) {
        return $query->where(['user_id' => $user_id]);
    }
]);

doc by with https://www.yiiframework.com/doc/api/2.0/yii-db-ac...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question