If you want to develop a module that has both EAV Models and Flat Table Models, you are at right place.

Your module’s config.xml should be look like this. 

 

<config>

            ...

            <global>

            ...

            <models>   

            <demo>

                        <class>Sps_Demo_Model</class>

                        <resourceModel>demo_resource_eav_mysql4</resourceModel>

            </demo>

            <demo_resource_eav_mysql4>

                        <class>Sps_Demo_Model_Resource_Eav_Mysql4</class>           

                        <entities>

                        <thing>

                        <table>demo_things</table>

                        </thing>

                        </entities>

            </demo_resource_eav_mysql4>

            <demo_flat>

                        <class>Sps_Demo_Model_Flat</class>

                        <resourceModel>demo_flat_mysql4</resourceModel>

            </demo_flat>

            <demo_flat_mysql4>

                        <class>Sps_Demo_Model_Flat_Mysql4</class>

                        <entities>

                        <item>

                        <table>demo_items</table>

                        </item>

                        </entities>

            </demo_flat_mysql4>

            </models>

            <resources>

            <demo_write>

                        <connection>

                        <use>core_write</use>

                        </connection>

            </demo_write>

            <demo_read>

                        <connection>

                        <use>core_read</use>

                        </connection>

            </demo_read>

            <demo_setup>

                        <setup>

                        <module>Sps_Demo</module>

                        <class>Sps_Demo_Entity_Setup</class>

                        </setup>

                        <connection>

                        <use>core_setup</use>

                        </connection>

            </demo_setup>

            <demo_flat_write>

                        <connection>

                        <use>core_write</use>

                        </connection>

            </demo_flat_write>

            <demo_flat_read>

                        <connection>

                        <use>core_read</use>

                        </connection>

            </demo_flat_read>

            <demo_flat_setup>

                        <setup>

                        <module>Sps_Demo</module>

                        <class>Sps_Demo_Entity_Mysql4_Setup</class>

                        </setup>

                        <connection>

                        <use>core_setup</use>

                        </connection>

            </demo_flat_setup>

            </resources>

            ...

            </global>

            ....

</config>

 

 

Ensure your folder structure should looks like this:

/app/code/local/Sps/Demo

/app/code/local/Sps/Demo/Block

/app/code/local/Sps/Demo/controllers

/app/code/local/Sps/Demo/Entity

/app/code/local/Sps/Demo/Entity/Mysql4

/app/code/local/Sps/Demo/etc

/app/code/local/Sps/Demo/Model

/app/code/local/Sps/Demo/Model/Flat

/app/code/local/Sps/Demo/Model/Flat/Mysql4

/app/code/local/Sps/Demo/Model/Resource

/app/code/local/Sps/Demo/Model/Resource/Eav

/app/code/local/Sps/Demo/Model/Resource/Eav/Mysql4

/app/code/local/Sps/Demo/sql

/app/code/local/Sps/Demo/sql/modulename_setup

/app/code/local/Sps/Demo/sql/modulename_flat_setup

 

And here, put your install/upgrade scripts in their respective folders in /sql.

After that create these two Setup classes :-

 

<?php

class Sps_Demo_Entity_Setup extends Mage_Eav_Model_Entity_Setup

{

}

 

 

<?php

class Sps_Demo_Entity_Mysql4_Setup extends Mage_Core_Model_Resource_Setup

{

}

 

 

Define your models’ class names as default (Sps_Demo_Model_Thing and Sps_Demo_Model_Flat_Item).

For initialising your models, use these:

Mage::getModel("demo/thing");

Mage::getModel("demo_flat/item");