Welcome Guest, Not a member yet? Register   Sign In
Active record - same table multiple join?
#4

[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.


Messages In This Thread
Active record - same table multiple join? - by El Forum - 04-01-2010, 10:17 AM
Active record - same table multiple join? - by El Forum - 04-01-2010, 07:01 PM
Active record - same table multiple join? - by El Forum - 04-06-2010, 12:44 AM
Active record - same table multiple join? - by El Forum - 05-19-2010, 12:13 PM
Active record - same table multiple join? - by El Forum - 05-19-2010, 02:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB