Answer the question
In order to leave comments, you need to log in
How to filter data by related table?
Hello.
There are User and Company models.
class User extands ActiveRecord{
//
public function getCompany()
{
return $this->hasOne(Company::className(), ['user_id' => 'id']);
}
public function getIsCompany()
{
return $this->company ? true : false;
}
}
$query = User::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$query->where(['company' => false]);
Unknown column 'company'.
Answer the question
In order to leave comments, you need to log in
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$query->joinWith('company')->where(['is','user_id',null]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question