www.it-ebooks.info
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
ORM and Data Collections<br />
For this purpose, I have created the Interactive Magento Console (IMC), which is<br />
a shell script specially created for this book and inspired by Ruby's own Interactive<br />
Ruby Console (IRB). Follow these steps:<br />
1. The first thing we will need to do is to install the IMC. To do so, download<br />
the source files from https://g<strong>it</strong>hub.com/amacgregor/mdg_imc and<br />
extract them under your Magento test installation. The IMC is a simple<br />
Magento shell script that will allow us to test our code in real time.<br />
2. Once you extracted the script, log in to the shell of your virtualbox.<br />
3. Next, we will need to navigate to our Magento root folder. If you are using<br />
the default vagrant box, the installation is already provided; the root folder<br />
is located under /srv/<strong>www</strong>/ce1720/public_html/, and we navigate to <strong>it</strong> by<br />
running the following command line:<br />
$ cd /srv/<strong>www</strong>/ce1720/public_html<br />
4. Finally, we can start the IMC by running the following command line:<br />
$ php shell/imc.php<br />
5. If everything is installed successfully, we should see a new line starting w<strong>it</strong>h<br />
magento >.<br />
Magento Model Anatomy<br />
As we learned in the previous chapter, Magento Data Models are used to manipulate<br />
and access the data. The model layer is divided into two fundamental types, simple<br />
models and EAV, where:<br />
• Simple Models: These model implementations are simple mappings of one<br />
object to one table, meaning that our object attributes match each field and<br />
our table structure<br />
• Ent<strong>it</strong>y Attribute Value Models (EAV): These type of models are used to<br />
describe ent<strong>it</strong>ies w<strong>it</strong>h a dynamic number of attributes<br />
Note that <strong>it</strong> is important to clarify that not all Magento Models<br />
extend or Mage use the ORM. Observers are a clear example of<br />
simpler Model classes that are not mapped to a specific database<br />
table or ent<strong>it</strong>y.<br />
[ 58 ]<br />
<strong>www</strong>.<strong>it</strong>-<strong>ebooks</strong>.<strong>info</strong>