title: Magento - Integrity constraint violation: 1052 - Shipping Method
body: <p>The following code allows to add a column to orders/sales page in which displays the shipping method as shipping description containing all delivery carriers.</p>
  
  <p>_prepareCollection</p>
  
  <pre><code>$collection-&gt;getSelect()-&gt;join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('shipping_description'));
  </code></pre>
  
  <p>_prepareColumn</p>
  
  <pre><code>$this-&gt;addColumn('shipping_method', array(
  'header' =&gt; Mage::helper('sales')-&gt;__('Shipping Method'),
  'index' =&gt; 'shipping_description',
  'filter_index' =&gt; 'main_table.status',
  ));
  </code></pre>
  
  <p>The shipping method appears perfect after I compile everything. Now when I try to sort the orders by prcessing and hit on Search it comes to this error:</p>
  
  <pre><code>SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'status' in where clause is ambiguous, query was: SELECT COUNT(*) FROM `sales_flat_order_grid` AS `main_table` INNER JOIN `sales_flat_order` ON main_table.entity_id = sales_flat_order.entity_id WHERE (status = 'processing')
  </code></pre>
  
  <p>After some research it means that there is a double status when tables are jointed, now how to I create an alians from this and how to I apply it. Also if anybody knows the way to filter/sort by this column would be awesome.</p>
  
  <p>PS. The file is located at:
  app/code/local/Mage/Adminhtml/Block/Sales/Order</p>
  
  <p><strong>EDIT:</strong> Now am trying to figure out how to create options dropdown based on the values in the database. Here is the code I am trying to get to work:</p>
  
  <pre><code>private static $_deliveryGroups = array();
  
  public static function getDeliveryArray() {
  if (count(self::$_deliveryGroups) == 0) {
      $delivery_group = new Mage_Shipping_Model_Group();
      $delivery_groups = $delivery_group-&gt;getColection()-&gt;toOptionHash();
      self::$_deliveryGroups = $delivery_groups;
  }
  return self::$_deliveryGroups;
  }
  </code></pre>
  
  <p>And additional values in the Grid.php</p>
  
  <pre><code>    $this-&gt;addColumn('shipping_method', array(
      'header' =&gt; Mage::helper('sales')-&gt;__('Shipping Method'),
      'renderer'  =&gt; 'Vehence_Module_Block_Adminhtml_Block_Sales_Order_Desc',
      'type' =&gt; 'options',
      'options' =&gt; Vehence_Module_Block_Adminhtml_Block_Sales_Order_Desc::getDeliveryArray(),
      ));
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>protected function _getAttributeOptions($attribute_code)
      {
          $attribute = Mage::getModel('sales/order')-&gt;getAttribute('shipping_description', $attribute_code);
          $options = array();
          foreach( $attribute-&gt;getSource()-&gt;getAllOptions(true, true) as $option ) {
              $options[$option['value']] = $option['label'];
          }
          return $options;
  }
  </code></pre>