0

I'm displaying data in a grid using a prepareColumns function.

I have two tables I want to join table "admin_user"

to:

table "customer_group" where both have 'customer_group_id' and I want to display the 'customer_group_code' from the "customer_group" table

I did something similar to this before to display the admin role ID using this code:

$collection = Mage::getResourceModel('admin/user_collection');
 $collection->getSelect()->join(
 array('ar' =>'admin_role'),
 'ar.user_id = main_table.user_id'
 ) ->join(
 array('ar2' => 'admin_role'),
 'ar.parent_id = ar2.role_id',
 array('role_name')
 );

I then tried to add onto the collection using:

$collection->getSelect()->join(
 array('ar' => 'admin_role'),
 'ar.customer_group_id = customer_group.customer_group_id',
 array('customer_group_code')
 );

But this gives me an error :( not sure what's wrong.

asked Mar 23, 2017 at 18:40

1 Answer 1

0

Ah foolish of me I realized main_table is the table I'm already currently in. I just had to join them as if they were two separate tables then look at customer_group_code in the second table.

Here is the code I used incase anyone has this problem:

$collection->getSelect()->join(
 array('cg' => 'customer_group'),
 'main_table.customer_group_id = cg.customer_group_id',
 array('customer_group_code')
 );
answered Mar 23, 2017 at 18:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.