1

I have a custom collection which pretty much only consists of product entity ids. I'd like to display a lot of other attributes from EAV tables, but these are all stored in the value column, which results in an error

Error Code: 1052 Column 'value' in field list is ambiguous

What kind of join method can I use in my _prepareCollection(); method?

I've tried:

$collection->getSelect()->join('catalog_product_entity_varchar', '`catalog_product_entity_varchar`.attribute_id=56 AND `catalog_product_entity_varchar`.entity_id = `main_table`.`product_id`', array('name'  => new Zend_Db_Expr((`catalog_product_entity_varchar`.value)));

Which works for one attribute, but if I try more than one I get the ambiguity issue even though I am specifying the parent table.

Would appreciate any assistance

  • Can you give an example of how you are getting it for multiple attributes? If you are using multiple joins to get the different attributes you could give a different alias to the table catalog_product_entity_varchar in each join – Paras Sood Aug 28 '14 at 9:30
2

You should use an alias when you join tables like that, e.g.

$collection->getSelect()->join(
    array('at_name' => 'catalog_product_entity_varchar'),
    'at_name.attribute_id = 56 AND at_name.entity_id = main_table.product_id',
    array('name' => 'at_name.name')
);

Now you can join catalog_product_entity_varchar more than once. There are probably better ways to access EAV data though, use direct SQL only if you know what you are doing.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.