A overview for those familiar with making flat models:
_construct()
codegetDefaultEntities()
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:
Mage_Eav_Model_Entity_Collection_Abstract
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
and increment_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
Can't be bothered to read? Just use these Show archive.org snapshot . Gists don't allow subdirectories, so I've used underscores.