tags:

views:

31

answers:

1

Hi

How can I use fk and m2m relations in magento? I read about EAV and I understand the benefits but I don't understand how to approach common problems in relational databases.

For example, I have products that should match several type of cars. Each car has make,model,year. With regular tables I'll have a Car table and I'll have m2m relation from each product to this table. Then, I can filter by car and reference the user's car in the order.

How can I implement cars and relate them to products in magento and how can I save the user's car in the order?

Thanks

A: 

The ORM Provided by Magento's Framework does not support many to many relationships. If you need to provide this type of functionality for additional Magento functionality you'll need to use a different ORM system, or write your SQL queries manually.

If you want to stick to the Magento core files, I'd investigate the Zend_Db* files that come bundled in lib.

Remember, while there's a lot of cool Framework features in Magento, it wasn't built to be a general purpose development framework. It was built to service the needs of Varien/Magento Inc in building an Ecommerce Platform.

Alan Storm
Magento has configurable products. Several configurable products can reference several Simple Products. Isn't that a m2m relation?Can I use Zend_Db and create my own table? How can I point the product to a row in my table?
pablo
1. I'm not super familiar with the object hierarchy behind configurable products, but one configurable product references many simple products. I'm pretty sure Simple product objects don't have a reference to any configurable product they're a part of, so that's a 1 to Many relationship. I could be wrong on that. If you find out something different be sure to let the community know!
Alan Storm
1 to many relationship is a good start. How do I create it? Can I have relationship to a custom table?
pablo
Hey Alan. You're correct on there being no m2m relationship code builpt in, but configurable products are many-to-many (a simple product can belong to many configurable products). See the table catalog_product_super_link.
Joseph Mastey
Cool, thanks for the correction. Good to know they're keeping track of the relationship properly!
Alan Storm