使用Magento将平台加入EAV表?

时间:2010-10-26 20:44:30

标签: collections join magento model

我正在尝试管理一个Adminhtml Grid,它将我称之为“facility”的表连接到“customer_entity”及其所有属性。

我注意到,由于我的表是平的,并且模型继承了Mage_Core_Model_Mysql4_Collection_Abstract,我无法使用我在后端看到的所有class_methods作为示例。

我已经成功地将我的表连接到customer_entity表,执行以下操作:

  $collection = Mage::getModel('facility/facility')->getCollection()
                ->join('customer/entity', 'customer_id = entity_id');

但是,我真正需要的只是获取客户名称。有帮助吗?

2 个答案:

答案 0 :(得分:3)

客户名称不存储在一个字段中,它们是名字,中间名和姓氏的组合;并取决于设置,前缀和后缀也是如此。客户类有为您组合这些的方法。

$collection = Mage::getModel('customer/customer')->getCollection()
              ->addNameToSelect()
              ->joinTable('facility/facility', 'entity_id=customer_id', array('*'));

joinTable方法是EAV集合的一部分,这就是为什么你不会在基于MySQL4的核心集合中看到它。第一个参数不是文字表名,而是config.xml中描述的实体表。

答案 1 :(得分:1)

一般来说,我同意previous answer对语法的一些更正


    $collection = Mage::getModel('customer/customer')->getCollection()
                  ->addNameToSelect()
                  ->joinTable('facility/facility', 'customer_id=entity_id', array('*'), null, 'right');

null part是一个WHERE子句,'right'是连接的类型

或者更好的决定是:


    $collection = Mage::getModel("facility/facility")->getCollection()->getSelect()->join('customer_entity', 'entity_id=customer_id', array('*'));