<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Magento Design and Development &#187; eav</title>
	<atom:link href="http://inchoo.net/tag/eav/feed/" rel="self" type="application/rss+xml" />
	<link>http://inchoo.net</link>
	<description>Magento Design and Magento Development Professionals - Inchoo</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:42:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Creating an EAV based model(s) in Magento</title>
		<link>http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/</link>
		<comments>http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 12:58:14 +0000</pubDate>
		<dc:creator>Branko Ajzele</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[eav]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://inchoo.net/?p=11755</guid>
		<description><![CDATA[Magento database heavily utilizes an Entity-Attribute-Value (EAV) data model. However, the cost of flexibility is often complexity. The process of manipulating EAV data in Magento is often more difficult than manipulating flat relational tables. All Magento Models inherit from the &#8230;<p><a href="http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/">Read more</a><p>]]></description>
			<content:encoded><![CDATA[<p>Magento database heavily utilizes an Entity-Attribute-Value (EAV) data model. However, the cost of flexibility is often complexity. The process of manipulating EAV data in Magento is often more difficult than manipulating flat relational tables.</p>
<p>All Magento Models inherit from the Mage_Core_Model_Abstract. Difference between simple Model or an EAV Model is its Model Resource. </p>
<p>To build a model with proper collection object in Magento you need 4 things<span id="more-11755"></span>:</p>
<ul>
<li>model class</li>
<li>resource class</li>
<li>collection class</li>
<li>install script (the one found under mymodule_setup folder of your extension)</li>
</ul>
<style>
.gist-highlight .line {
	height:auto!important;
	float:none!important;
	float:none!important;
	background:none!important;
}
</style>
<p>To extend this little further there is one more file you would most likely need when building an EAV based model, the Setup.php which extends from Mage_Eav_Model_Entity_Setup. You would need to implement the getDefaultEntities() method in it as this is what&#8217;s called during the extension installation in Magento.</p>
<p>Imagine your module is called Phonebook and put into the /Inchoo namespace under the local code pool. Logically you would need a model class like User which represents single entry into the phonebook. With this in mind you already need a structure like:</p>
<ul>
<li>app/etc/modules/Inchoo_Phonebook.xml</li>
<li>app/code/local/Inchoo/Phonebook/etc/config.xml</li>
<li>app/code/local/Inchoo/Phonebook/Model/User.php</li>
<li>app/code/local/Inchoo/Phonebook/Model/Resource/User.php</li>
<li>app/code/local/Inchoo/Phonebook/Model/Resource/User/Collection.php</li>
<li>app/code/local/Inchoo/Phonebook/Model/Resource/Setup.php</li>
<li>app/code/local/Inchoo/Phonebook/sql/inchoo_phonebook_setup/install-1.0.0.0.php</li>
</ul>
<p>Now that we outlined the file structure, let&#8217;s get down to it and see what the content of files should look like in order for it to work.</p>
<p>app/etc/modules/Inchoo_Phonebook.xml<br />
<script src="https://gist.github.com/1430081.js?file=gistfile1.xml"></script></p>
<p>app/code/local/Inchoo/Phonebook/etc/config.xml<br />
<script src="https://gist.github.com/1430085.js?file=gistfile1.xml"></script></p>
<p>app/code/local/Inchoo/Phonebook/Model/User.php<br />
<script src="https://gist.github.com/1430086.js?file=gistfile1.aw"></script></p>
<p>app/code/local/Inchoo/Phonebook/Model/Resource/User.php<br />
<script src="https://gist.github.com/1430090.js?file=gistfile1.aw"></script></p>
<p>app/code/local/Inchoo/Phonebook/Model/Resource/User/Collection.php<br />
<script src="https://gist.github.com/1430091.js?file=gistfile1.aw"></script></p>
<p>app/code/local/Inchoo/Phonebook/Model/Resource/Setup.php<br />
<script src="https://gist.github.com/1430096.js?file=gistfile1.aw"></script></p>
<p>app/code/local/Inchoo/Phonebook/sql/inchoo_phonebook_setup/install-1.0.0.0.php<br />
<script src="https://gist.github.com/1430098.js?file=gistfile1.aw"></script></p>
<p>For each attribute type like &#8220;varchar&#8221;, &#8220;text&#8221;, &#8220;int&#8221;&#8230; you need to create a corresponding table like inchoo_phonebook_user_entity_varchar, inchoo_phonebook_user_entity_text, inchoo_phonebook_user_entity_int. Study the install-1.0.0.0.php and the config.xml file to see how to get that one done.</p>

<a href='http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/attachment/snap_2011-12-04_13h06m02s_001_/' title='Snap_2011.12.04_13h06m02s_001_'><img width="300" height="165" src="http://inchoo.net/wp-content/uploads/2011/12/Snap_2011.12.04_13h06m02s_001_-300x165.png" class="attachment-thumbnail" alt="Snap_2011.12.04_13h06m02s_001_" title="Snap_2011.12.04_13h06m02s_001_" /></a>
<a href='http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/attachment/snap_2011-12-04_13h07m00s_003_core-resource-blog-localhost-table/' title='Snap_2011.12.04_13h07m00s_003_core-resource -blog -localhost- - Table'><img width="300" height="235" src="http://inchoo.net/wp-content/uploads/2011/12/Snap_2011.12.04_13h07m00s_003_core-resource-blog-localhost-Table-300x235.png" class="attachment-thumbnail" alt="Snap_2011.12.04_13h07m00s_003_core-resource -blog -localhost- - Table" title="Snap_2011.12.04_13h07m00s_003_core-resource -blog -localhost- - Table" /></a>
<a href='http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/attachment/snap_2011-12-04_13h07m34s_004_-nibccapture-02f1dcaf-8f72-4627-b675-014a58d4f832/' title='Snap_2011.12.04_13h07m34s_004_-nibCCapture-02f1dcaf-8f72-4627-b675-014a58d4f832'><img width="300" height="176" src="http://inchoo.net/wp-content/uploads/2011/12/Snap_2011.12.04_13h07m34s_004_-nibCCapture-02f1dcaf-8f72-4627-b675-014a58d4f832-300x176.png" class="attachment-thumbnail" alt="Snap_2011.12.04_13h07m34s_004_-nibCCapture-02f1dcaf-8f72-4627-b675-014a58d4f832" title="Snap_2011.12.04_13h07m34s_004_-nibCCapture-02f1dcaf-8f72-4627-b675-014a58d4f832" /></a>
<a href='http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/attachment/snap_2011-12-04_13h08m10s_005_eav-entity-type-blog-localhost-table/' title='Snap_2011.12.04_13h08m10s_005_eav-entity-type -blog -localhost- - Table'><img width="300" height="157" src="http://inchoo.net/wp-content/uploads/2011/12/Snap_2011.12.04_13h08m10s_005_eav-entity-type-blog-localhost-Table-300x157.png" class="attachment-thumbnail" alt="Snap_2011.12.04_13h08m10s_005_eav-entity-type -blog -localhost- - Table" title="Snap_2011.12.04_13h08m10s_005_eav-entity-type -blog -localhost- - Table" /></a>
<a href='http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/attachment/snap_2011-12-04_13h11m03s_006_inchoo-phonebook-user-entity-blog-localhost-table/' title='Snap_2011.12.04_13h11m03s_006_inchoo-phonebook-user-entity -blog -localhost- - Table'><img width="300" height="199" src="http://inchoo.net/wp-content/uploads/2011/12/Snap_2011.12.04_13h11m03s_006_inchoo-phonebook-user-entity-blog-localhost-Table-300x199.png" class="attachment-thumbnail" alt="Snap_2011.12.04_13h11m03s_006_inchoo-phonebook-user-entity -blog -localhost- - Table" title="Snap_2011.12.04_13h11m03s_006_inchoo-phonebook-user-entity -blog -localhost- - Table" /></a>
<a href='http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/attachment/snap_2011-12-04_13h11m18s_007_inchoo-phonebook-user-entity-int-blog-localhost-table/' title='Snap_2011.12.04_13h11m18s_007_inchoo-phonebook-user-entity-int -blog -localhost- - Table'><img width="300" height="204" src="http://inchoo.net/wp-content/uploads/2011/12/Snap_2011.12.04_13h11m18s_007_inchoo-phonebook-user-entity-int-blog-localhost-Table-300x204.png" class="attachment-thumbnail" alt="Snap_2011.12.04_13h11m18s_007_inchoo-phonebook-user-entity-int -blog -localhost- - Table" title="Snap_2011.12.04_13h11m18s_007_inchoo-phonebook-user-entity-int -blog -localhost- - Table" /></a>
<a href='http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/attachment/snap_2011-12-04_13h11m32s_008_inchoo-phonebook-user-entity-text-blog-localhost-table/' title='Snap_2011.12.04_13h11m32s_008_inchoo-phonebook-user-entity-text -blog -localhost- - Table'><img width="300" height="215" src="http://inchoo.net/wp-content/uploads/2011/12/Snap_2011.12.04_13h11m32s_008_inchoo-phonebook-user-entity-text-blog-localhost-Table-300x215.png" class="attachment-thumbnail" alt="Snap_2011.12.04_13h11m32s_008_inchoo-phonebook-user-entity-text -blog -localhost- - Table" title="Snap_2011.12.04_13h11m32s_008_inchoo-phonebook-user-entity-text -blog -localhost- - Table" /></a>
<a href='http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/attachment/snap_2011-12-04_13h11m42s_009_inchoo-phonebook-user-entity-varchar-blog-localhost-table/' title='Snap_2011.12.04_13h11m42s_009_inchoo-phonebook-user-entity-varchar -blog -localhost- - Table'><img width="300" height="181" src="http://inchoo.net/wp-content/uploads/2011/12/Snap_2011.12.04_13h11m42s_009_inchoo-phonebook-user-entity-varchar-blog-localhost-Table-300x181.png" class="attachment-thumbnail" alt="Snap_2011.12.04_13h11m42s_009_inchoo-phonebook-user-entity-varchar -blog -localhost- - Table" title="Snap_2011.12.04_13h11m42s_009_inchoo-phonebook-user-entity-varchar -blog -localhost- - Table" /></a>
<a href='http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/attachment/model-4/' title='model'><img width="300" height="118" src="http://inchoo.net/wp-content/uploads/2011/12/model-e1323080904528-300x118.jpg" class="attachment-thumbnail" alt="model" title="model" /></a>

<p>Finally, you can test your model and it’s collection by running the following somewhere in your code:<br />
<script src="https://gist.github.com/1430101.js?file=gistfile1.aw"></script></p>
<p>And that&#8217;s it. Although simple, there is some typing to be done in order to get the EAV based model functional. Hope it helps someone. </p>
<p>Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Magento’s database layout and its EAV structure</title>
		<link>http://inchoo.net/ecommerce/magento/magentos-database-layout-and-its-eav-structure/</link>
		<comments>http://inchoo.net/ecommerce/magento/magentos-database-layout-and-its-eav-structure/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 10:01:38 +0000</pubDate>
		<dc:creator>Mladen Lotar</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[eav]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://inchoo.net/?p=5428</guid>
		<description><![CDATA[Greetings fellow developers! Today I&#8217;ll try to explain the principles of EAV system and Magento&#8217;s implementation of it. This is a tutorial / explenation for beginners, so please be patient and even try to draw the logic on a paper &#8230;<p><a href="http://inchoo.net/ecommerce/magento/magentos-database-layout-and-its-eav-structure/">Read more</a><p>]]></description>
			<content:encoded><![CDATA[<p>Greetings fellow developers! Today I&#8217;ll try to explain the principles of EAV system and Magento&#8217;s implementation of it. This is a tutorial / explenation for beginners, so please be patient and even try to draw the logic on a paper if you don&#8217;t understand it. A small notice before we start. I won&#8217;t use specific SQL query examples since this will be a simplified example of principles of the EAV.<br />
<span id="more-5428"></span></p>
<h3>What is EAV?</h3>
<p>EAV stands for Entity, Attribute and Value. And that&#8217;s where we begin with our story.</p>
<p><strong>Entity</strong> is somewhat of a &#8220;data item&#8221;. In Magento, those are for example Categories, Products and Customers.</p>
<p><strong>Attribute</strong> is again a &#8220;data item&#8221;, but to differ it from the Entity, in Magento, attributes are for example: Title, Description, Price, etc. for each Product entity.</p>
<p>And <strong>Value</strong> for simplicity of explanation represents &#8220;real value&#8221; that is attached to Entity&#8217;s Attribute</p>
<p><strong>And now, how does it work? (a.k.a. The Fun Part)</strong></p>
<h3>Part 1 &#8211; saving the data</h3>
<p>Again, for the sake of simplicity, let&#8217;s use a Product in Magento for example.</p>
<p>If you&#8217;ve ever added a new product to Magento, you know that you&#8217;ve had to add some title, description and price to it (there are more attributes but we are using 3 for this example). When you saved your product, you used a total of 3 tables to save that information (a few more, but those are irrelevant for our example). First, a new Entity was added to DB, second, In Attribute table, you saved attributes (title, description and price) attached to that product, and finally to Value table, you saved 3 rows, attached to that product&#8217;s attributes. Here&#8217;s a simplified schema for those 3 tables:</p>
<p><img class="alignnone size-full wp-image-5429" title="simplified_eav" src="http://inchoo.net/wp-content/uploads/2010/09/simplified_eav.jpg" alt="" width="496" height="250" /></p>
<p>Let&#8217;s say that our inserted product got the ID value of 1, our attributes got IDs from 1-3 and values where assigned to attributes accordingly.</p>
<h3>Part 2 &#8211; getting the data</h3>
<p>This is the easy part to understand. Retrieving the data from any EAV system begins at Entity. First, you get the Product entity&#8217;s (in our example 1)  ID, then, you get it&#8217;s attributes and values accordingly. That&#8217;s about it regarding retrieving the data from EAV system.</p>
<p><strong>The conclusion</strong></p>
<p>Well, I hope you understood the above example, in Magento&#8217;s EAV. I say Magento&#8217;s because there can be (and there are) different variations regarding the EAV&#8217;s complexity, but the principle is same for all of them.</p>
<p>Why is EAV used?</p>
<p>It&#8217;s used because of scalability. You can add almost anything into DB without changing it&#8217;s structure. That would be the main pron of it.</p>
<p>But everything that has a pron, has a con too. <img src='http://inchoo.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Major problem with EAV systems is that each of them is much slower than a custom made solution because of SQL complexity. You need quite a few joins on DB just to retrieve one single Entity (or &#8220;data item&#8221;) in opposite to, let&#8217;s say, one select query on a custom made solution.</p>
<p>After this brief explanation. You should understand why Magento uses EAV system. It uses it because Magento is designed to be scalable, regardless of speed problems.</p>
<p>I&#8217;ve attached a <a href="http://inchoo.net/wp-content/uploads/2010/09/MAGENTO_v1.3.2.4-Database_Diagram.pdf">PDF of Magento&#8217;s DB structure</a> (v. 1.3), so that you can see the complexity (and simplicity) of it. And a <a href="http://en.wikipedia.org/wiki/Entity-attribute-value_model" target="_blank">wiki refference</a>.</p>
<p>I hope this helped somebody, and that you now understand that once you comprehend EAV&#8217;s logic, it&#8217;s quite simple. <img src='http://inchoo.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>P.S. Before me, two of my colleagues wrote  articles that are closely related to the EAV discussions. Tomislav Bilic firstly introduced <a href="http://inchoo.net/ecommerce/magento/magento-mysql-database-structure/">Magento MySQL database diagram</a> back in 2008, while last year Branko Ajzele opened a discussion on <a href="http://inchoo.net/ecommerce/magento/escape-from-eav-the-magento-way/">how to Escape from EAV the Magento way</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoo.net/ecommerce/magento/magentos-database-layout-and-its-eav-structure/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Magento 1.4 new things in EAV attributes</title>
		<link>http://inchoo.net/ecommerce/magento/magento-1-4-new-things-in-eav-atributes/</link>
		<comments>http://inchoo.net/ecommerce/magento/magento-1-4-new-things-in-eav-atributes/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 10:41:54 +0000</pubDate>
		<dc:creator>Domagoj Potkoc</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[eav]]></category>

		<guid isPermaLink="false">http://inchoo.net/?p=4183</guid>
		<description><![CDATA[If you install new version of Magento 1.4, you can see that existing differences in structures of eav attributes. Earlier all data of EAV attributes were in table eav_attribute, now in new version eav_attribute table is smaller, beacuse a lot &#8230;<p><a href="http://inchoo.net/ecommerce/magento/magento-1-4-new-things-in-eav-atributes/">Read more</a><p>]]></description>
			<content:encoded><![CDATA[<p>If you install new version of Magento 1.4, you can see that existing differences in structures of eav attributes. Earlier all data of EAV attributes were in table <strong>eav_attribute</strong>, now in new version eav_attribute table is smaller, beacuse a lot of fileds moved in new tables.<br />
<span id="more-4183"></span><br />
<strong>Structure of mysql table eav_attribute, Magento version 1.4:</strong><br />
<a href="http://inchoo.net/wp-content/uploads/2010/03/eav_attributes_magento1.4.jpg"><img src="http://inchoo.net/wp-content/uploads/2010/03/eav_attributes_magento1.4-637x300.jpg" alt="" title="eav_attributes_magento1.4" width="637" height="300" class="alignnone size-medium wp-image-4186" /></a></p>
<p><strong>Structure of mysql table eav_attribute, Magento version 1.3:</strong><br />
<a href="http://inchoo.net/wp-content/uploads/2010/03/eav_attributes_magento1.3.jpg"><img src="http://inchoo.net/wp-content/uploads/2010/03/eav_attributes_magento1.3-637x514.jpg" alt="" title="eav_attributes_magento1.3" width="637" height="514" class="alignnone size-medium wp-image-4188" /></a></p>
<p>In new version of Magento, we have new table as: <strong>catalog_eav_attribute, customer_eav_attribute</strong> and so on&#8230;..</p>
<p>One important thing: the model <strong>Mage_Eav_Model_Entity_Setup</strong> has changes in new version of Magento.  I have a problems with update attributes.</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoo.net/ecommerce/magento/magento-1-4-new-things-in-eav-atributes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Escape from EAV the Magento way</title>
		<link>http://inchoo.net/ecommerce/magento/escape-from-eav-the-magento-way/</link>
		<comments>http://inchoo.net/ecommerce/magento/escape-from-eav-the-magento-way/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 23:01:04 +0000</pubDate>
		<dc:creator>Branko Ajzele</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[eav]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://inchoo.net/?p=2182</guid>
		<description><![CDATA[One of the differences between Magento eCommerce platform and lets say WordPress, when looked from developer point of view, is &#8220;avoid raw queries&#8221; approach. For a web application, Magento is massive system. His database, although not so massive but surely &#8230;<p><a href="http://inchoo.net/ecommerce/magento/escape-from-eav-the-magento-way/">Read more</a><p>]]></description>
			<content:encoded><![CDATA[<p>One of the differences between Magento eCommerce platform and lets say WordPress, when looked from developer point of view, is &#8220;avoid raw queries&#8221; approach. For a web application, Magento is massive system. His database, although not so massive but surely breathtaking with around 220 tables forces you to use &#8220;eye candy&#8221; EAV model to do even simple things.<span id="more-2182"></span></p>
<p>For instance, if I were to tell you that I want you to retrieve 5 simple products from database that have price in the range of 200-600USD you would most likely spent 1-4 hours trying to work out the query. In the end you would be lucky if you even get the query that wont break on next Magento upgrade. Let me just remind you on some of the things you need to be careful in example above.</p>
<p>Your query would have to take in consideration the at least the following states: is my product visibility such that it can be seen in Catalog and search result, is my product enabled or disabled, is is out of stock, which website and store view has it been assigned, is it assigned to only one category and that category is disabled by some chance, does it have special price assigned, does it have promotion rules assigned, does it have content (descriptions) for multilingual site assigned.</p>
<p>All of those and more are questions that one has to take into consideration when doing raw database queries. It makes no sense to create query that fetches product and all its appropriate info (price, quantity, description&#8230;) if that product is disabled or assigned to category that is disabled. For instance, if you need &#8220;featured&#8221; product functionality and you manually create raw query that extracts one &#8220;featured&#8221; product to lets say home page. There you create nice block holding all the necessary info of the product with a link for lets say &#8220;Add to cart&#8221; or &#8220;View product&#8221;. Clicking one of those two link would give you most likely 404 if the product is disable or any other condition that enables the product to be shown is disabled.</p>
<p>So basically, raw SQL queries in Magento are a &#8220;no no&#8221; for most of the time. Too much work and you never know what they will change in future upgrades. Which brings me to this new trend of theirs which I like to call &#8220;Escape from EAV&#8221;.</p>
<p><a title="The Soul is trying to escape from Hell // The Gates of Hell" href="http://en.wikipedia.org/wiki/The_Gates_of_Hell" target="_blank"><img class="size-full wp-image-2282 alignright" title="Gates of Hell" src="http://inchoo.net/wp-content/uploads/2009/06/gates_of_hell.jpg" alt="Gates of Hell" width="310" height="324" /></a>EAV, also know as Entity Attribute Value was suppose to bee (or is) the next big thing in OOP. Anyhow, Magento and his way of EAV have two huge downfalls called LACK OF DOCUMENTATION and WHAT WILL THEY CHANGE IN NEXT UPGRADE. The other day I was working on a Magento  shop that had 22 000 products. Almost all of them were simple products, just about 600 were grouped. The store was initially installed on Magento 1.2 version. Site was pretty much 95% complete from both graphic and development perspective. Anyhow, Magento version 1.3.1 was released and on client demand we decide to to upgrade. Important thing to keep in mind is that in version 1.3 Magento introduce &#8220;change in philosophy&#8221; concerning the EAV model.</p>
<p>Altough EAV sounds great (and really is great for most of the time), it can really slow things down with all those JOINS executed on database. So the Magento team decided to do a little flat tabling. Basically we now have massive data duplication in MySQL where data is taken from various tables and copied int one, the flat table. Flat tables were introduced for both Products and categories, in regards to various website and store views.</p>
<p>Basically Magento has the power to &#8220;on the fly&#8221; create tables and do the &#8220;magical&#8221; copying of data from various tables to the flat tables. I assume they were looking for a faster way to &#8220;assemble&#8221; Product objects in Magento which in turn should boost the speed of collection object i grew so found about. I can live with duplicated data in database, I mean I am not the one writing them down. But let me get back to real world scenario.</p>
<p>As I mentioned, store I have been working on had more than 20 000 products. Due to limitations of both MySQL and PHP failed to do Rebuilt that you can find in System &gt; Configuration &gt; Cache management. This failure caused corrupted data in database. This manifested with &#8220;empty&#8221; attributes (attributes not showing up in Layered navigation). I resolved the issue by &#8220;re saving&#8221; all of the 20 000 product with custom script I wrote. After that i noticed the data in flat tables got rebuild as well. This of course took several hours. Magento EAV model seems OK on paper, but with store that hold&#8217;s large number of products it simply does not work, at least not in way in which their collection objects are built. Changes introduced in form of flat tables in versions 1.3  should, to some extent, improve work with stores that have large numbers of products. However this improvement seems to come in form of &#8220;copy all data from scattered tables to single flat table&#8221;.</p>
<p>Solutions like these are nightmare when it comes to upgrading the store that already has large number of products in. System is expected to handle part of the job transparently but it failed, leaving the client with corrupted database.</p>
<p>So, a word of advice for upgrading an existing Magento store: NEVER do it on live site. Let professional developer transfer live site and database to his dev machine, or make a copy on some sub folder on live site. Magento&#8217;s extreme out of the box feature rich capabilities, open source philosophy and good marketing have made it extremely popular but be careful, free is such a a loose term.</p>
<p>I am really anxious to see the future path of EAV vs Flat model in Magento.</p>
<p>PS. This topic was discussed on two more following articles from my colleagues. Tomislav Bilic firstly introduced <a href="http://inchoo.net/ecommerce/magento/magento-mysql-database-structure/">Magento MySQL database diagram</a> back in 2008, while Mladen Lotar expanded this intro and provided more details at his <a href="http://inchoo.net/ecommerce/magento/magentos-database-layout-and-its-eav-structure/">Magento’s database layout and it’s EAV structure</a> article at 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoo.net/ecommerce/magento/escape-from-eav-the-magento-way/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Magento MySQL database diagram</title>
		<link>http://inchoo.net/ecommerce/magento/magento-mysql-database-structure/</link>
		<comments>http://inchoo.net/ecommerce/magento/magento-mysql-database-structure/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 21:36:00 +0000</pubDate>
		<dc:creator>Tomislav Bilic</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[eav]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://inchoo.net/?p=241</guid>
		<description><![CDATA[If you worked with osCommerce, Zen Cart, CRE Loaded or any similar eCommerce platform before, you might find Magento database structure quite confusing when you see it for the first time. I advise you not to rush too much figuring &#8230;<p><a href="http://inchoo.net/ecommerce/magento/magento-mysql-database-structure/">Read more</a><p>]]></description>
			<content:encoded><![CDATA[<p>If you worked with osCommerce, Zen Cart, CRE Loaded or any similar eCommerce platform before, you might find Magento database structure quite confusing when you see it for the first time. I advise you not to rush too much figuring out what is what by glancing through database. Try to spend first few hours getting familiar with some background. For purposes of flexibility, the Magento database heavily utilizes an Entity-Attribute-Value (EAV) data model. As is often the case, the cost of flexibility is complexity. Is there something in Magento that is simple from developers point of view?</p>
<p><span id="more-241"></span></p>
<p>Data manipulation in Magento is often more knowledge demanding  than that typical use of traditional relational tables. Therefore, an understanding of EAV principles and how they have been modeled into Magento it is HIGHLY recommended before making changes to the Magento data or the Magento schema (<a class="urlextern" title="http://en.wikipedia.org/wiki/Entity-attribute-value_model" rel="nofollow" href="http://en.wikipedia.org/wiki/Entity-attribute-value_model">Wikipedia: Entity-attribute-value_model</a>). Varien has simplified the identification of EAV related tables with consistent naming conventions. Core EAV tables are prefixed with “EAV_”. Diagrams in this post contain a section labeled “EAV” which displays Magento’s core EAV tables and thier relationships to non-EAV tables.</p>
<p><img class="alignnone size-medium wp-image-236" title="layout_example1" src="http://inchoo.net/wp-content/uploads/2008/10/layout_example1-637x352.png" alt="" width="637" height="352" /></p>
<p><a href="http://inchoo.net/wp-content/uploads/2008/10/magento_v116-database_diagram.pdf">Download Magento 1.1.6 MySQL database diagram (PDF)</a><br />
<a href="http://inchoo.net/wp-content/uploads/2010/09/MAGENTO_v1.3.2.4-Database_Diagram.pdf">Download Magento 1.3.2.4 MySQL database diagram (PDF)</a></p>
<p>Database diagrams and documents found in this post are intended to mirror the database schema as defined by Varien. Table relationships depicted in the diagrams represent <strong>only those relationships explicitly defined as Foreign Keys in the Magento database</strong>. Additional informal/undiagrammed table relationships may also exist, so when modifying the schema or directly manipulating data it is important to identify and evaluate possible changes to these tables as well (and the tables they relate to, and the tables they relate to&#8230;).</p>
<p>The author of Database Diagram is Gordon Goodwin, IT Consultant. You can see his info in the PDF.</p>
<p>PS. This topic was discussed on two more following articles from my colleagues. Mladen Lotar expanded this intro and provided more details at his <a href="http://inchoo.net/ecommerce/magento/magentos-database-layout-and-its-eav-structure/">Magento’s database layout and it’s EAV structure</a> article at 2010, while in 2009. Branko Ajzele opened a discussion of <a href="http://inchoo.net/ecommerce/magento/escape-from-eav-the-magento-way/">how to Escape from EAV the Magento way</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoo.net/ecommerce/magento/magento-mysql-database-structure/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

