R
R
Roman Kuzmenko2016-05-16 10:23:07
MySQL
Roman Kuzmenko, 2016-05-16 10:23:07

How to make a multi-table select model in Yii2?

Hello! I started to study Yii2, please tell me how to organize a model to return query information from several tables?
The request looks like this:

SELECT tbc.id_client, tbco.birth_date FROM tb_client tbc JOIN tb_contact tbco ON (tbco.id_client=tbc.id_client) where id_reg in (SELECT id_reg FROM tb_reg WHERE id_person = 465)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Кирилл Арутюнов, 2016-05-16
@arutyunov

www.yiiframework.com/doc-2.0/guide-db-active-recor...

Максим Федоров, 2016-05-16
@qonand

the solution depends on the task:
if you need to get related data for one record, use lazy loading https://github.com/yiisoft/yii2/blob/master/docs/g...
if you need to get related data for many records (for example, for table building) use eager loading https://github.com/yiisoft/yii2/blob/master/docs/g...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question