开发者

Join a Flat Table to an EAV Table with Magento?

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 bac开发者_Go百科kend.

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?


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.


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('*'));

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜