Search code examples
databasemagentoentity-attribute-value

Multiple table access in a custom module


I am new to Magento. I need two table in my custom module and I have to load two table as separate collection, ie Mage::getModel('mymodule/model1')->getcollection() and Mage::getModel('mymodule/model2')->getcollection()

I've followed the link posted here Magento - possible to have multiple tables for a single model? but I am stuck. I created two model classes "model1" and "model2", and created same under the "mysql4", my first model works fine, but if I accessed second one it's not working.

How could I use multiple table in a single module?
Thanks in advance.


Here is my config.xml

<models>
    <module>
        <class>Package_Module_Model</class>
        <resourceModel>module_mysql4</resourceModel>
    </module>
    <module_type1>
        <class>Package_Module_Model_Type1</class>
        <resourceModel>module_mysql4</resourceModel>
    </module_type1>
    <module_mysql4>
        <class>Package_Module_Model_Mysql4</class>
        <entities>
            <module>
                <table>table1</table>
            </module>
            <module_type1>
                <table>table2</table>
            </module_type1>
        </entities>
    </module_mysql4>


Solution

  • You only have one module so only need one module declaration:

    <models>
        <module>
            <class>Package_Module_Model</class>
            <resourceModel>module_mysql4</resourceModel>
        </module>
        <module_mysql4>
            <class>Package_Module_Model_Mysql4</class>
            <entities>
                <model1>
                    <table>table1</table>
                </model1>
                <model2>
                    <table>table2</table>
                </model2>
            </entities>
        </module_mysql4>
    </models>
    

    Here there are several models in a single module's entities list.