views:

45

answers:

1

Hi,

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?

+1  A: 

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.

clockworkgeek