I have a test set-up which involves many to many relation.
Students Model
id
name
[b]
Parents Model[/b]
id
name
Students_Parents Model
student_id
parent_id
What I am trying to do is redirecting student update form to parent grid view. I want to show the related students parent records only in the parents grid view.
for example mysql query to show the related record is like this:
SELECT s.id, s.name, p.id, p.name
FROM `students` s, parents p, student_parent sp
WHERE s.id = sp.student_id
AND p.id = sp.parent_id
AND s.id =102
and in the controller I could find the same record like this when I use the data of student with the id of 102
$model2 = Students_Parents::find()
->where(['student_id' => $model->id])
->all();
my redirect code in controller I am trying to do is:
if(isset($_POST['parents'])){
return $this->redirect(['parents/index','id'=>$model2]);
}
Here the form is redirecting correctly, but no filter is applied.
How can I incorporate the query in redirect so I get the related data only in the GridView.
Thanks