3

I confused by following collection classes

  1. $orders = Mage::getResourceModel('sales/order_item_collection');
  2. $orders = Mage::getResourceModel('sales/order');
  3. $orders = Mage::getResourceModel('sales/order_collection');

    Whats the difference among those classes.

And whats difference between

Mage::getModel('sales/order');

and

 Mage::getResourceModel('sales/order');
5
  1. Mage::getResourceModel('sales/order_item_collection') = Mage_Sales_Model_Resource_Order_Item_Collection this is the resource for a collection of items in orders, normally the database table that this is attached to is sales_flat_order_item
  2. Mage::getResourceModel('sales/order') = Mage_Sales_Model_Resource_Order is the resource for a single sales orders and works with table sales_flat_order
  3. Mage::getResourceModel('sales/order_collection') = Mage_Sales_Model_Resource_Order_Collection and this is the resource for the collection of orders and uses the table sales_flat_order.

The main difference between models, resources and collections is described as follows:

  1. Model: these classes are used to representing a single item normally from the database,
  2. Resource: these classes are used to fetch and save data for an item to the database,
  3. Collection: these classes are used to deal with more than one item from the database,
-1

They are all get different objects. They are all different files. They all serve different purposes. See here on how to use collections: https://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento See here for Magento Models and ORM Basics: https://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-5-magento-models-and-orm-basics

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.