Magento 1.9 EAV – How to Join Two Entity Tables

eaventitiesmagento-1.9

I have created a custom entity table vaibhav_customtabs_product_entity, where I have following columns.

entity_id
entity_type_id
attribute_set_id
increment_id
store_id
created_at
updated_at
is_active
product_id (entity_id from 'catalog_product_entity')

Now my question is how do I join catalog_product_entity & vaibhav_customtabs_product_entity tables, based on the product entity id. So that, I can fetch the attribute value from my custom entity.
Also from both the entity.

Best Answer

$collection = Mage::getModel('catalog/product')->getCollection(); 

$collection->getSelect()->join(
                        array('cust' => $collection->getTable('vaibhav/customtabs')),
                        'cust.product_id' = 'main_table.entity_id'); 

$this->setCollection($collection); 

parent::_prepareCollection();

return $this;

I'm assuming vaibhav/customtabs is you folder structure module_name

Here is a very good reference on how this works with Magento and using a flat and an EAV table. About 1/2 down you will see about 'Validating Your Bind'. In this case, that's your issue. I could write everything in here, but this reference should give you what you looking for. Good Luck and let us know how it turns out!

http://blog.fabian-blechschmidt.de/joining-a-flat-table-on-eav/