I want to join three tables on every time when model load (for example on edit from page, on grid page in admin and detail page in front-end etc… ) in my custom module. can you please let me know where is best place to code for this (in model class, in resource class or collection class) and what function I should use for joining?
please help me to fix this.
Edited:
<?xml version="1.0"?>
<config>
<modules>
<Mynamespace_Mymodule>
<version>1.0.4</version>
</Mynamespace_Mymodule>
</modules>
<global>
<resources>
<mynamespace_mymodule_setup>
<setup>
<module>Mynamespace_Mymodule</module>
<class>Mynamespace_Mymodule_Model_Resource_Setup</class>
</setup>
</mynamespace_mymodule_setup>
</resources>
<blocks>
<mynamespace_mymodule>
<class>Mynamespace_Mymodule_Block</class>
</mynamespace_mymodule>
</blocks>
<helpers>
<mynamespace_mymodule>
<class>Mynamespace_Mymodule_Helper</class>
</mynamespace_mymodule>
</helpers>
<models>
<mynamespace_mymodule>
<class>Mynamespace_Mymodule_Model</class>
<resourceModel>mynamespace_mymodule_resource</resourceModel>
</mynamespace_mymodule>
<mynamespace_mymodule_resource>
<class>Mynamespace_Mymodule_Model_Resource</class>
<entities>
<table1>
<table>mynamespace_mymodule_table1</table>
</table1>
<table2>
<table>mynamespace_mymodule_table2</table>
</table2>
<table3>
<table>mynamespace_mymodule_table3</table>
</table3>
</entities>
</mynamespace_mymodule_resource>
</models>
</global>
<adminhtml>
<layout>
<updates>
<mynamespace_mymodule>
<file>mynamespace_mymodule.xml</file>
</mynamespace_mymodule>
</updates>
</layout>
</adminhtml>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Mynamespace_Mymodule before="Mage_Adminhtml">Mynamespace_Mymodule_Adminhtml</Mynamespace_Mymodule>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
Thanks in advance!
Best Answer
techguy4web,
In this case,you need make one table primary table and using join function
[left join,Inner join]
on Resource Model and Resource Model Collection class relationrest of two classes
.Add Tables into Model Collection :
You need to first work on collection class.Here,you need do add function
_afterLoad()
on collection class,w using this function you can mapping relation between there table.On Resource Class : Mynamespace_Mymodule_Model_Resource_Mymodel_Collection
afterLoad() trigger a perform a operations after collection load.
Add Three tables into model
On resource class you need add multiple table using function _getLoadSelect() on Mynamespace_Mymodule_Model_Resource_Mymodel
If resource collection is not work then try this code at collection.php
Create two individual function.which is include rest of function to collection.
You can use: