Answer the question
In order to leave comments, you need to log in
How to make a selection for several categories at once. Yii2?
I have a two level menu, the categories are related by id and parent_id in the CATEGORY table.
Products in a particular category are displayed by category_id in the CATEGORY table.
I need to display products in the parent category from all child ones.
Tell me how can this be done? Or maybe someone will lead somewhere.
Thank you very much in advance)
Answer the question
In order to leave comments, you need to log in
if you have a maximum nesting level of 2 (i.e. category and subcategory) then you can select products from the parent category with something like this query:
SELECT
*
FROM
product
WHERE
category_id IN (
SELECT
id
FROM
category
WHERE
parent_id = 2
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question