title: How to get data for an entity (for example customer) from eav_attribute table to be shown in Customer Grid for admin
body: <p>I have extended Magento’s customer information form to store an additional attribute for customer. Lets call it ‘customer_referrer_id’.</p>
  
  <p>I have a role ‘referrer ‘ who has access to customer grid and order grid only. But, I want to restrict a referrer to see only those customers in the grid who have the customer_referrer_id set as the referrer’s id who has logged in. Similarly for orders, the logged in referrer shall be able to see only those orders made by customers who have customer_referrer_id = loggedin_referrer_id.</p>
  
  <p>I already know how to override a module and that I have to mainly override Adminhtml/Block/Customer/Grid::_prepareCollection and Adminhtml/Block/Sales/Order/Grid::_prepareCollection</p>
  
  <p>I am using Magento 1.4.1.1 </p>
  
  <p>This is my module declaration file in app/etc/modules/Myproject_Adminhtml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  
  &lt;config&gt;
      &lt;modules&gt;
          &lt;Myproject_Adminhtml&gt;
              &lt;active&gt;true&lt;/active&gt;
              &lt;codePool&gt;local&lt;/codePool&gt;
              &lt;depends&gt;
                  &lt;Mage_Sales /&gt;
              &lt;/depends&gt;
          &lt;/Myproject_Adminhtml&gt;
      &lt;/modules&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p>And my modules config.xml in local/Myproject/Adminhtml/etc/ is as follows:</p>
  
  <pre><code>&lt;config&gt;
      &lt;modules&gt;
          &lt;Myproject_Adminhtml&gt;
              &lt;version&gt;1.0.0&lt;/version&gt;
          &lt;/Myproject_Adminhtml&gt;    
      &lt;/modules&gt;
  
      &lt;global&gt;
            &lt;blocks&gt;
              &lt;adminhtml&gt;
                  &lt;rewrite&gt;
                  &lt;sales_order_grid&gt;Myproject_Adminhtml_Block_Sales_Order_Grid&lt;/sales_order_grid&gt;
                  &lt;customer_grid&gt;Myproject_Adminhtml_Block_Customer_Grid&lt;/customer_grid&gt;
                  &lt;/rewrite&gt;
              &lt;/adminhtml&gt;
          &lt;/blocks&gt;
      &lt;/global&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p>And </p>
  
  <pre><code>class Myproject_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Customer_Grid
  {
      protected function _prepareCollection()
      {
          $collection = Mage::getResourceModel('customer/customer_collection')
          -&gt;addNameToSelect()
          -&gt;addAttributeToSelect('email')
          -&gt;addAttributeToSelect('created_at')
          -&gt;addAttributeToSelect('group_id')
          -&gt;joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
          -&gt;joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
          -&gt;joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
          -&gt;joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
          -&gt;joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');    
  
          $this-&gt;setCollection($collection);
  
          $referrer_id = Mage::getSingleton('admin/session')-&gt;getUser()-&gt;getId();
          Mage::log('Logged in admin has id: ' . $referrer_id);
  
          return parent::_prepareCollection();
      }  
  }
  </code></pre>