E
E
Evgeny Musonov2020-02-26 12:28:44
Yii
Evgeny Musonov, 2020-02-26 12:28:44

Is it possible to specify join at the end of each query through the model?

There is a database, it contains information about goods. Goods have a manufacturer.
The connection between the product and the manufacturer is carried out through an intermediate table.
Task: display products of a certain manufacturer only. Everything is complicated by the fact that there are a lot of queries to the product table and they are scattered throughout the project, and some of them already contain different joins.

Tried to make my own ActiveQuery

class ProductQuery extends ActiveQuery
{
  public function init()
  {
    $this->innerJoin('product_properties', 'product.id = product_properties.product_id')
      ->innerJoin('property_value',  'property_value.id = product_properties.property_value_id')
      ->andWhere(['property_value.name' => 'Лунный свет (Испания)']);
    return parent::init(); // TODO: Change the autogenerated stub
  }
}

The number of goods increases several times, I suspect that joins overlap.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-02-26
@evmusonov

I don't recommend doing that. You probably do not need such a connection everywhere. If you want to optimize queries, then read my answer on this topic: What are the best ways to form database queries in Yii2?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question