Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: Does Mage::getModel('catalog/category') Use EAV or Flat Data?

Tags:

magento

When you call Mage::getModel('catalog/category') or Mage::getModel('catalog/product'), does that load from the flat data or the _entity table?

There is an option in the admin that let you "use flat" data, and I'm wondering if this is related to the ::getModel() call.

like image 787
musicliftsme Avatar asked Jan 24 '26 03:01

musicliftsme


1 Answers

The catalog/category model is an EAV model. In a default Magento configuration, its data is stored in

catalog_category_entity
catalog_category_entity_datetime
catalog_category_entity_decimal
catalog_category_entity_int
catalog_category_entity_text
catalog_category_entity_varchar

The catalog/category model also has a "flat catalog" feature in System -> Configuration -> Catalog -> Use Flat Catalog Category. With this enabled the catalog/category model will pull data from one of the flat categories

catalog_category_flat_store_*

Either way, you can use the catalog/category collection object to query this data any way you see fit, including the addAttributeToFilter method.

$collection = Mage::getModel('catalog/category')
    ->getCollection()
    ->addAttributeToSelect('*');

$collection->addAttributeToFilter(
    'url_path', array('like' => 'apparel%')
);

foreach($collection as $item)
{
    var_dump($item->getData());
}
like image 86
Alan Storm Avatar answered Jan 26 '26 23:01

Alan Storm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!