Home » Interview Question » difference between addAttributeToSelect(), addAttributeToFilter() and addFieldToFilter() methods

difference between addAttributeToSelect(), addAttributeToFilter() and addFieldToFilter() methods

difference between addAttributeToSelect(), addAttributeToFilter() and addFieldToFilter() methods

addAttributeToSelect() : addAttributeToSelect() is used to filter the attributes fromthe magento database

addAttributeToFilter : addAttributeToFilter() is used to filter EAV collections in Magento,and filter the products based on the attributes that you have included in your collection.

addAttributeToFilter add a condition to the WHERE part of the MySQL query, used to extract a product collection from the database using specified condition.

The above code would get a product collection, with each product having it’s name, price AND sku. The product collection would be filtered and contain only products that have an SKU WITH with AM.
If we use addAttributeToSelect(‘*’), then all product attributes will be loaded.

addFieldToFilter : addFieldToFilter will filter the products based on columns in the database from the table catalog_product_entity. and used for flat model.it is defined in Mage_Core_Model_Resource_Db_Collection_Abstract class so it is available in all its child classes.

, , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">