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

[eluser]Vheissu[/eluser]
[quote author="mawi27" date="1282736959"]
Quote: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?


Jakobud,

what you descripe happens to all columns with the same name in your joined tables. The most right column will be the only in the result.
I ran into the same problem, and found no way to use aliases with AR but manually write the select statement as you have done as alternative.
Maybe an AR expert can give us some help here, or takes this issue (using column aliases for joined tables) to the AR feature request list.

Marco

@ToddyBoy
there is definitely no difference for this issue using the object or array result set.

@Veishu
this is a standard SQL requirement. Only because you want to join 2 tables, there is no obvious need for an ORM i would say. For using DMZ your tables and relations have to follow special conventions, which is o.k. but doesn't suit everyone.[/quote]

He was asking if you can access field names in tables specifically using Active Record much like an ORM would let you do, like this; $this->users->id which would be saying I want to access the ID field of the users table (like the example the question asker provided) and the answer is Active Record can't do that.

Sure an ORM might be something new to learn and cause you to rewrite your queries, but if you want to access tables and field names like objects, an ORM is the way to go and not Active Record.

The purpose of Active Record is to simplify queries you otherwise would be writing manually like tedious joins.


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