2
Table 1
--------------
|reseller_id |
|1           |
|2           |
|3           |
|4           |
--------------

Table 2
-------------------------------
|reseller_id | merchandise_id |
|1           | 1              |
|1           | 3              |
|2           | 1              |
|2           | 4              |
|3           | 2              |
-------------------------------

select * from reseller_maps inner join reseller_merch on reseller_maps.reseller_id = reseller_merch.reseller_id;

在数据库方面给了我我正在寻找的东西。但是,我得到一个

 Call to undefined method Namespace_Class_Model_Mysql4_Reseller_Collection::joinTable() 

尝试在 Magento 中执行 $collection->joinTable() 时。

我试过使用 getSelect 和 join():

        $collection = Mage::getModel('maps/reseller');
        $collection->getSelect()
            ->join( array( 'reseller_merch'=>$this->getTable('reseller_merch')), 'reseller_maps.reseller_id= reseller_merch.reseller_id', array('reseller_merch.*'));

我得到:

 SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ''

据我所知,这是直接来自 wiki 上的示例代码:http: //www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento

4

1 回答 1

1

假设您正在对标准集合进行子类化,它应该是:

$collection->getSelect()->join($this->getTable('maps/[table_entity]'), 'main_table.reseller_id= reseller_merch.reseller_id');

这是假设您的实体以这种方式命名。

于 2012-11-13T19:36:33.013 回答