Welcome Guest, Not a member yet? Register   Sign In
How to get table.column in active record queries?
#1

[eluser]Jakobud[/eluser]
Lets say I have two tables: users and roles

Each table has a column called 'id'.

If I use active record to query the values of the joined tables:

Code:
$this->db->join('role', 'role.id = user.role_id');
$query = $this->db->get('user');

foreach ( $query->result() as $row )
    echo $row->id; // <--- this is the problem right here

The 'id' that the active record query prints out is the 'id' column from the role table. But what if I want to print out the id from the user table? Is there anyway to specify it implicitly like this?

Code:
echo $row->user.id

The only alternative I've found so far is to specify what I'm selecting first:

Code:
$this->db->select('user.id AS user_id, role.id AS role_id');

But I thought perhaps there was a different way to do it with active record... Any thoughts?


Messages In This Thread
How to get table.column in active record queries? - by El Forum - 08-24-2010, 06:23 PM
How to get table.column in active record queries? - by El Forum - 08-24-2010, 06:39 PM
How to get table.column in active record queries? - by El Forum - 08-24-2010, 09:47 PM
How to get table.column in active record queries? - by El Forum - 08-25-2010, 12:49 AM
How to get table.column in active record queries? - by El Forum - 08-25-2010, 01:17 AM
How to get table.column in active record queries? - by El Forum - 08-25-2010, 08:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB