Welcome Guest, Not a member yet? Register   Sign In
Field prefix when using join in active record
#1

[eluser]inari[/eluser]
This is my problem:

$q = $this->db->join('partners','partners.client = clients.id','left');
$q = $this->db->get('clients')->result();

Both tables have at least one field that has exact name. In this case there are fields called 'name', 'address', etc...

When I get output, fields with same name are overwritten.

Is there some way to use field prefix with codeigniter? So if there are two fields with same name that I can get one field like 'test_name', and other one like 'clients_name'

If not, is there some auto-aliases with mysql or something like that?

Only way I can use same field names now is that I white sql manually an use 'AS' alias.
But I can't use it with Active record.
#2

[eluser]Rob Stefanussen[/eluser]
You can use aliases with AR:

Also, there is no need to assign the return of your first line to a variable; try something like this:

Code:
$this->db->select('partners.client AS c1, clients.id AS c2');
$this->db->join('partners', 'c1 = c2', 'left');
$result = $this->db->get('clients')->result();
#3

[eluser]inari[/eluser]
Hm, it's not really working..

"Unknown column 'c1' in 'on clause'"
#4

[eluser]Rob Stefanussen[/eluser]
Could you post the output of:

Code:
$this->db->last_query();
#5

[eluser]inari[/eluser]
No, it can't show output with errors messages together.

I think there is only table prefix support but not for fields.




Theme © iAndrew 2016 - Forum software by © MyBB