M
M
Maxim Timofeev2017-05-18 12:53:19
Yii
Maxim Timofeev, 2017-05-18 12:53:19

How to make connection with OR?

I drove myself with such a base:
id | article_id | product_id |company_id
In the Forum model, I make a connection with this model to select everything where product_id = product_id or company_id = company_id
So far I have this:

public function getRelatedArticles(){
        return $this->hasMany(ArticleRelation::className(),['product_id'=>'product_id'])->union($this->hasMany(ArticleRelation::className(),['company_id'=>'company_id']));
    }

It works, but the thought that this is hellish idiocy does not leave me. I think to get away from communication in general and just make a selection. But communication is more convenient. Any ideas?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
padlyuck, 2017-05-18
@padlyuck

$this->hasMany returns ActiveQueryInterface , you can try to use some one instead of hasMany

$query = ArticleRelation::find()->where(/*ваши фильтры*/);
$query->multiple = true;
return $query;

Haven't tried it myself, but it might work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question