2

I have to add Extra field like buyer name in Admin sales order create section

Mage_Adminhtml_Block_Sales_Order_Create_Search_Grid

In collection Add code like

 $collection->getSelect()->join( 
        't2'=>'table2_to_be_joined',
        'main_table.table_field_id ='t2.field_id', array('field_name'));

New products field are coming excellently.

now we need to add one more table

field to check table_2 field_name == table_3 field_name must equal.

After adding this join query result

$collection->getSelect()->join( array(
      't2'=>'table2_to_be_joined', 't3' => 'table3_to_be_joind'),
        'main_table.table_field_id ='t2.field_id' and 't2.field_name = t3.field_name',array('field_name'));

Its showing

Unknown column 't3.field_name' in 'on clause', query

2
  • I have a doubt that , you have joined the table and it is updated in DB. Later you wish to add additional field in any one of the table. Then you have to write update query to join the table once again.right?
    – Jaisa
    Commented Feb 10, 2018 at 9:18
  • If it has entry already, It will show "You cannot define a correlation name more than once" issue how do u solve
    – Jaisa
    Commented Feb 10, 2018 at 9:19

1 Answer 1

3

Try

 $collection->getSelect()->join( 
    array('t2'=>'table2_to_be_joined'),
    'main_table.table_field_id = t2.field_id',
     array('t2.field_name')
  );

  $collection->getSelect()->join( 
    array('t3'=>'table3_to_be_joind'),
    't2.field_name = t3.field_name'
    array('t3.field_name')
  );
3
  • HI R.S, Thanks for your ANS. But its shows Item (Mage_Catalog_Model_Product) with the same id "3189" already exist Commented Sep 28, 2015 at 13:54
  • Without seeing the data set it hard to figure out why, but the error message is stating that it is returning 2 rows with the same id; so you may add a "group by" or "distinct" Commented Sep 28, 2015 at 14:00
  • Please remember to accept Commented Sep 29, 2015 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.