[eluser]patwork[/eluser]
Hi,
I'm trying to do same thing, and I'm afraid it's not working properly.
CodeIgniter's activerecord creates query like this:
Code:
SELECT `st_id`, `table1`.`us_login`, `table2`.`us_login`
FROM (`stream`)
LEFT JOIN `users` AS table1 ON `table1`.`us_id` = `stream`.`st_id_user_from`
LEFT JOIN `users` AS table2 ON `table2`.`us_id` = `stream`.`st_id_user_to`
That way, you will loose fields with duplicated names:
Code:
object(stdClass)
public 'st_id' => string '1'
public 'us_login' => string 'somelogin'
I have managed to fix this, by adding "AS name" to every field:
Code:
SELECT `st_id`, `table1`.`us_login` AS t1_login, `table2`.`us_login` AS t2_login
...
Which in result gave me:
Code:
object(stdClass)
public 'st_id' => string '1'
public 't1_login' => string 'somelogin'
public 't2_login' => string 'someotherlogin'
Frankly, I can't imagine how to create such a query for fields with wildcards, like "SELECT st_id, table1.*, table2.*", because names of keys in results arrays have only fields names, without tables.