Collections 使用Magento将平面桌子连接到EAV桌子?

Collections 使用Magento将平面桌子连接到EAV桌子?,collections,join,magento,model,Collections,Join,Magento,Model,我正在尝试创建一个Adminhtml网格,它将我创建的名为“facility”的表连接到“customer\u entity”及其所有属性 我注意到,由于我的表是平面的,并且模型继承了fomr Mage_Core_model_Mysql4_Collection_Abstract,所以我无法使用我在后端看到的所有类方法作为示例 我已成功地通过以下操作将我的表连接到customer_entity表: $collection = Mage::getModel('facility/facility'

我正在尝试创建一个Adminhtml网格,它将我创建的名为“facility”的表连接到“customer\u entity”及其所有属性

我注意到,由于我的表是平面的,并且模型继承了fomr Mage_Core_model_Mysql4_Collection_Abstract,所以我无法使用我在后端看到的所有类方法作为示例

我已成功地通过以下操作将我的表连接到customer_entity表:

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

然而,我真正需要的只是得到客户的名字。有什么帮助吗

客户名称不存储在一个字段中,它们是名字、中间名和姓氏的组合;根据设置,前缀和后缀也可以。customer类为您提供了组合这些功能的方法

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

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

客户名称不存储在一个字段中,它们是名字、中间名和姓氏的组合;根据设置,前缀和后缀也可以。customer类为您提供了组合这些功能的方法

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

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

一般来说,我同意对语法进行一些更正

$collection = Mage::getModel('customer/customer')->getCollection() ->addNameToSelect() ->joinTable('facility/facility', 'customer_id=entity_id', array('*'), null, 'right'); $collection=Mage::getModel('customer/customer')->getCollection() ->addNameToSelect() ->joinTable('facility/facility','customer_id=entity_id',数组('*'),null,'right'); null部分是WHERE子句,“right”是联接的类型

或者更好的决定是:

$collection = Mage::getModel("facility/facility")->getCollection()->getSelect()->join('customer_entity', 'entity_id=customer_id', array('*')); $collection=Mage::getModel(“设施/设施”)->getCollection()->getSelect()->join('customer\u entity','entity\u id=customer\u id',array('*');
总的来说,我同意对语法的一些修改

$collection = Mage::getModel('customer/customer')->getCollection() ->addNameToSelect() ->joinTable('facility/facility', 'customer_id=entity_id', array('*'), null, 'right'); $collection=Mage::getModel('customer/customer')->getCollection() ->addNameToSelect() ->joinTable('facility/facility','customer_id=entity_id',数组('*'),null,'right'); null部分是WHERE子句,“right”是联接的类型

或者更好的决定是:

$collection = Mage::getModel("facility/facility")->getCollection()->getSelect()->join('customer_entity', 'entity_id=customer_id', array('*')); $collection=Mage::getModel(“设施/设施”)->getCollection()->getSelect()->join('customer\u entity','entity\u id=customer\u id',array('*');
在第二种方法中,如何获取客户名称?在第二种方法中,如何获取客户名称?如果我使用此方法,我得到了“具有相同id“xxx”的项目(Mage\u customer\u Model\u customer)”错误。@piavgh您的自定义表包含多条客户“xxx”的记录。确保您要加入的列的索引是唯一的。如果我使用此方法,则会出现“id为“xxx”的项(Mage\u Customer\u Model\u Customer)已存在”错误。@piavgh您的自定义表包含多条客户“xxx”的记录。确保要加入的列的索引是唯一的。