使用 Magento 将平面表连接到 EAV 表?

发布于 2024-09-29 09:12:42 字数 439 浏览 4 评论 0原文

我正在尝试创建一个 Adminhtml 网格,它将我制作的名为“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');

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

I am trying to manke an Adminhtml Grid which joins a table that I made called "facility" to "customer_entity" and all of its attribtues.

I'm noticing that since my table is flat, and the model inherits fomr Mage_Core_Model_Mysql4_Collection_Abstract, I'm not able to use all the class_methods that I've seen as examples on the backend.

I've successfully been able to join my table to the customer_entity table doing the following:

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

However, what I really need is just to get the customer name. Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幻想少年梦 2024-10-06 09:12:42

客户姓名不存储在一个字段中,而是由名字、中间名和姓氏组成;并且根据设置,还有前缀和后缀。客户类别有为您组合这些的方法。

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

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

Customer names are not stored in one field, they are a combination of first, middle and last name; and depending on settings, a prefix and suffix too. The customer classes have methods for combining these for you.

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

The joinTable method is part of EAV collections which is why you won't see it in the core MySQL4 based collections. The first parameter is not a literal table name but an entity table as described in your config.xml.

不必你懂 2024-10-06 09:12:42

一般来说,我同意 之前的答案,只是对语法

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

null 部分进行了一些更正,这是一个 WHERE 子句,“正确”是类型加入

或者也许更好的决定是:

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

Generally I agree with the previous answer just some corrections to the syntax

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

null part is a WHERE clause and the 'right' is the type of the join

Or maybe a better decision is:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文