Answer the question
In order to leave comments, you need to log in
How, in my case, to do a search in a CRUD application on yii2?
I write CRUD Applications. I want to do field search with join.
My code in the model
public function getIdVacancy() {
return $this->status->id_vacancy;
}
$query->joinWith(['status' => function ($q) {
$q->where('status.id_vacancy LIKE "%' . $this->idVacancy . '%"');
}]);
public function getVacancyNumber()
{
return $this->status->vacancy->code;
}
<code> $query->joinWith(['status' => function ($q) {
$vacancy_id = \backend\models\Vacancy::find()->where( 'title LIKE "%' . $this->titleVacancy . '%"')->one()->id;
$q->where('status.id_vacancy LIKE "%' . $vacancy_id . '%"');
}]);</code>
Answer the question
In order to leave comments, you need to log in
Is the relation Status declared in the model? + Is the Vacancy relation declared in the Status model?
If yes, then you can do this:
$query->joinWith(['status s', 'status.vacancy v'])->where([
'like',
's.id_vacancy',
$this->idVacancy
])->andWhere([
'like',
'v.title',
$this->titleVacancy
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question