Overview
A overview for those familiar with making flat models:
- Your config is standard, your table name takes the form of the base (entity) table
- You name your resource models as normal (so by class name, you can't tell the difference between flat and EAV)
- You make your domain model as normal
- Your resource model extends a different class and has different
_construct()
code - Your resource collection model extends a different class, but is otherwise the same
- You make your entity and value tables using setup DDL as you would with any table
- Your entity types, attributes, sets and groups are set up for you by using
getDefaultEntities()
A Bit More In-depth
Slightly more in depth, but pretty rough:
-
Set up your config as normal
-
Make your domain model as normal
-
Create your resource model as normal, but with two exceptions:
-
Extend
Mage_Eav_Model_Entity_Abstract
-
_construct()
should look like this:/** * Resource initialization */ protected function _construct() { $resource = Mage::getSingleton('core/resource'); $this->setType('entity_type_code')->setConnection( $resource->getConnection('yourmodule_read'), $resource->getConnection('yourmodule_write') ); }
-
-
Make a collection as normal, but with one exception:
- Extend
Mage_Eav_Model_Entity_Collection_Abstract
- Extend
-
Make your setup resource, remember to extend
Mage_Eav_Model_Entity_Setup
for EAV goodness -
In your setup class, make a
getDefaultEntities()
method to install your entities. See the file examples at the bottom for what this looks like -
Make a setup script which calls
$installer->installEntities();
. Note that this only sets up the entity types, attributes and sets - it doesn't make the actual tables, the below stuff does that -
Add table creation to your setup script. You might think there is a lovely magic way of doing this, well you'd be right, but no-one uses it because it's overbearing in the sense it creates ALL the possible value tables you could ever want (you might not need them all) and it also adds
store_id
andincrement_id
to the entity table, which are most likely pointless for your needs, so instead Magento simply uses normal DDL creation statements to make all the tables - yep, that's a lot of code! See the file examples at the bottom for what this looks like
The Files
Can't be bothered to read? Just use these Show archive.org snapshot . Gists don't allow subdirectories, so I've used underscores.