Answer the question
In order to leave comments, you need to log in
How to select related data in Yii2?
Tell me how you can select related, but so that the combined data is not in the add. column a in rows.
for example:
model Category(id, title), model Page(id, title, category_id)
form activequery and as a result we get:
line 1 - id_1/category1/
line 2 - id_1/title1_model_page (for category 1)
line 3 - id_2/title2_model_page (for category 1)
line 4 - id_1 / category 2 /
line 5 - id_1 / title1_model_page (for category 2)
or at least tell me how it is possible to form a query in sql, it is by lines that you need to collect related data.
Да есть вариант собрать все данные в массив(сделав цикл по списку категорий и по каждой категории выбрав посты), но данных может быть много и хотелось бы использовать итератор(batch или each).
А весь этот массив с данными я пытаюсь запихнуть в сюда https://github.com/codemix/yii2-excelexport чтобы экспортировать в ексель.
Answer the question
In order to leave comments, you need to log in
используйте UNION www.mysql.ru/docs/man/UNION.html
SELECT id, title FROM categories
UNION
SELECT category_id as id, title FROM page
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question