Access data from 2 tables in a custom Magento module

I need help. I created a custom module in magento that needs to interact with multiple tables.

I used the following to get table names

 <entities>
     <support1>
       <table>table1</table>
     </support1>
     <support2>
       <table>table2</table>
     </support2>   
     <support3>
       <table>table3</table>
     </support3>      
  </entities>

Then I added to my model

following:
  public function _construct()
 {
     parent::_construct();
     $this->_init('support/support1');
     $this->_init('support/support2');
     $this->_init('support/support3');
 }

In mysql4 folder i have ...

 public function _construct()
 {
     $this->_init('support/support1', 'ticket_id');
     $this->_init('support/support2', 'dept_id');
     $this->_init('support/support3', 'priority_id');
 }

And in Collection.php I have ...

public function _construct()
 {
     parent::_construct();
     $this->_init('support/support1');
     $this->_init('support/support2');
     $this->_init('support/support3');
 }

So using

$collection = Mage::getModel('support/support')->getCollection();

How can I determine access to support1 or support2, etc. I tried using ...

$collection = Mage::getModel('support/support1')->getCollection();

and

$collection = Mage::getModel('support/support')->getCollection('support1');

but both failed, how should this work?

Thanks in advance.

+5
source share
2 answers

Magento does not have a "one module, one data class" structure. Instead, a single module may contain many different models. Each class of the model refers to one table.

, ,

Package_Support_Model_Support                             //model
Package_Support_Model_Resource_Mysql4_Support             //model resource
Package_Support_Model_Resource_Mysql4_Support_Collection  //collection

- , Magento.

, 1,

Package_Support_Model_Support1                             //model
Package_Support_Model_Resource_Mysql4_Support1             //model resource
Package_Support_Model_Resource_Mysql4_Support_Collection1  //collection

Mage::getModel('support/support1');

, 1.

StackOverflow, , , .

+11

|-/Model
|---Support1.php
|---Support2.php
|---Support3.php
|------Mysql4
|--------Support1.php
|--------Support1
|----------Collection.php
|--------Support2.php
|--------Support2
|----------Collection.php
|--------Support3.php
|--------Support3
|----------Collection.php


class <CompanyName>_<ModuelName>_Model_Support[x] extends Mage_Core_Model_Abstract

class <CompanyName>_<ModuelName>_Model_Mysql4_Support[x] extends Mage_Core_Model_Mysql4_Abstract

class <CompanyName>_<ModuelName>_Model_Mysql4_Support[x]_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
+3

All Articles