Object Relational Mapping (ORM)
Most Magento Models can categorized in one of two way.There’s a basic,ActiveRecord-like/one-object-one-table Model, andthere’s also anEntity Attribute Value (EAV) Model. There’s alsoModelCollections.
Collections arePHP objects used to hold a number of individual Magento Model instances.
Magento Models don’t contain any code for connectingto the database.
When you instantiate a Model inMagento, you make a call like this
$model= Mage::getModel('weblog/blogpost');
The first part of the URI you pass into get Model istheModelGroup Name.The second part of the URI is the lowercase version of yourModel name.
All basic Models should extendtheMage_Core_Model_Abstract
class. Thisabstract class forces you to implement a single method named_construct
(NOTE: this is not PHP’sconstructor__consutrct
).This method should call the class’s _init method with the same identifying URIyou’ll be using in theMage::getModel
method call.
All Magento Models inherit from the the Varien_Object class. This class is partof the Magento system library andnot part ofany Magento core module.
resourcemodels are configured in the same section of the XML config as normal Models.
NOTE: Magento implements all magic functionality in the__call
method.
CRUD: MagentoModels support the basicCreate, Read, Update, and Delete functionalityof CRUD withload
,save
, anddelete
methods.Thesave method will allow you tobothINSERT a new Model into thedatabase, orUPDATE an existing one.
Collections: Ratherthan returning a simple array of Models, each Magento Model type has a uniquecollection object associated with it. These objects implement the PHPIteratorAggregate and Countable interfaces, which means they can be passed tothe count
function,and used inforeach
constructs.
Source From:http://alanstorm.com/magento_models_orm