I'm trying to get data from catalog_product EAV tables with the following code:

$productCollection = Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToFilter('type_id', ['eq' => Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE])
            ->addAttributeToFilter('status', ['eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED])

as you can see above, I have also called for some_custom_attribute to be sent with the result of the query.

Associated query for the above collection from getSelect() returns:

SELECT `e`.*, `at_status`.`value` AS `status` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`entity_id` = `e`.`entity_id`) AND (`at_status`.`attribute_id` = '96') AND (`at_status`.`store_id` = 0) WHERE (`e`.`type_id` = 'configurable') AND (at_status.value = 1))

The result of the query does not contain the name. However, when I do the following:

foreach ($productCollection as $product) {
            echo "Product is: ".$product->getId()." with name ".$product->getName()." with value of custom attribute ".$product->getSomeCustomAttribute()."\n";

It returns me the correct name of the product even though the name was not received as part of the query.

How is it that I'm able to get the value of name and some_custom_attribute even though the query result does not contain those columns?

1 Answer 1


The main select contains only the data from the entity table (catalog_product_entity which happens your case) or the flat table if you have enabled the option to use flat tables for product data (catalog_product_flat_X for example catalog_product_flat_1 for store 1). in the latter case the attributes would be listed in the main select.

If you don't use flat tables for product data, the loading of the attribute data from the eav tables is done after the loading of the entity in a separate method.

Please check the method Mage_Eav_Model_Entity_Collection_Abstract::load() for details:

There you can see a call $this->_loadEntities($printQuery, $logQuery); which loads the entity data and a second call $this->_loadAttributes($printQuery, $logQuery); which loads the eav attribute data and adds it to the corresponding collection item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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