So I have 3 tables named menus, products and categories.
menus table has id, item_type which can be product|category and item_id.
What I'd like to do is when menu item_type = product, join it with the products table ON products.id = menu.item_id and join with categories when item_type = category.
This is my current query:
SELECT m.* FROM menus m
LEFT JOIN products p ON p.id = m.item_id AND m.item_type = 'product'
LEFT JOIN categories c ON c.id = m.item_id AND m.item_type = 'category'
The query works though I'm not seeing any product or category data attached to each menu.
Am I missing something here? Thanks.