A
A
alex995052017-10-21 11:49:17
Yii
alex99505, 2017-10-21 11:49:17

How to properly build a SQL JOIN query in Yii2?

Tell me, is it possible to execute a join query using ActiveRecord in Yii2, or is it necessary to form the desired final table with separate queries?
In fact, you need to do the same as in this topic, only using Yii2. It is clear to me how to implement this with ordinary requests. It would be desirable, that with use of ActiveRecord.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-10-21
@slo_nik

Good afternoon.
Here, read, delayed and eager loading . Further in the article how to work with join.

M
Maxim Timofeev, 2017-10-21
@webinar

Tell me, is it possible to execute a join query using ActiveRecord in Yii2

SomeModel::find()
   ->joinWith('some_relation_name') //тут имя связи
   ->andWhere(['some_related_table_name.column_name'=>12]) //тут имя таблицы
   ->all();

It is possible without a connection, for this there is ->join() and ->leftJoin()
Everything is here:
www.yiiframework.com/doc-2.0/guide-db-active-recor...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question