A
A
Alem Nur2016-08-20 09:11:00
Yii
Alem Nur, 2016-08-20 09:11:00

How to build a complex Yii2 query using ActiveRecord?

How to build such a query in yii2 using ActiveRecord:

SELECT
  professions.professionID,
  professions.professionCode,
  professions.professionNameRU
FROM profession_cafedra
  INNER JOIN professions
    ON profession_cafedra.professionID = professions.professionID
  INNER JOIN cafedras
    ON profession_cafedra.cafedraID = cafedras.cafedraID
WHERE cafedras.FacultyID = 1

?
Are there similar examples?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-08-20
@slo_nik

Good morning.
The link describes everything in detail
https://github.com/yiisoft/yii2/blob/master/docs/g... (Using JOIN with links)

M
Maxim Timofeev, 2016-08-20
@webinar

Для начала надо создать связи в модели professions:
www.yiiframework.com/doc-2.0/guide-db-active-recor...
потом составить запрос используя joinWith:
описано там же в разделе "Joining with Relations"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question