Studyon Minte9.com
Magento




Models



ORM get you out of the business of writing SQL and allow you to manipulate a datastore purely through PHP code.

	$model = Mage::getModel('catalog/product')->load(27);
	$price = $model->getPrice();
	$price += 5;
	$model->setPrice($price)->setSku('SK83293432');
	$model->save(); 

In the above example we're calling the methods "getPrice" and "setPrice" on our Product. 
However, the Mage_Catalog_Model_Product class has no methods with these names. 
That's because Magento's ORM uses PHP's _get and _set magic methods. 

If you wanted to get all the available data on a Model, call $product->getData(); to get an array of all the attributes. 

Magento's ORM also contains a way to query for multiple Objects via a Collections interface. 
The following would get us a collection of all products that cost $5.00

	$products_collection = Mage::getModel('catalog/product')
	->getCollection()
	->addAttributeToSelect('*')
	->addFieldToFilter('price','5.00'); 

Collections use the PHP Standard Library to implement Objects that have array like properties.

	foreach($products_collection as $product) {
	    echo $product->getName();
	} 


http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-1-introduction-to-magento#5