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

[eluser]kaejiavo[/eluser]
Vheissu,

i don't disagree with you regarding ORM. But it is not the question here.

Please reread the original post:
Quote:If I use active record to query the values of the joined tables:

$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?

echo $row->user.id
The only alternative I’ve found so far is to specify what I’m selecting first:

$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?

There is a field 'id' in the user table and another one in the role table. As the role table is the most right in his join, only the role.id is part of his $query->result().
He has found an alternative, namely to alias the role.id so that it does not conflict with the user.id
The context is the foreach( $query->result() as $row ) where he uses the AR Methods to build his array or whatever. I cannot see a question about $this->users->id there.

Anyway, of course you can have a variable $this->users in your controller and with AR set the value as
$this->users = $this->db->row()
and then use $this->users->columnname in your code. I am absolutely sure this is working as i am using it in many places without ORM.

@Jakobud
sorry, i didn't want to hijack your thread, i stop posting here, now.


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