[eluser]patie[/eluser]
[quote author="WanWizard" date="1280969465"]If it's a one-to-many, that shouldn't be necessary, your FK should be ok like this.
You are doing something wrong somewhere, I just created a test database with your 4 tables, created the models, and ran the query I posted before.
Result:
Code:
SELECT `order_albums`.*, `orders`.`user_id` AS order_user_id, `orders`.`status` AS order_status, `order_users`.`id` AS order_user_id, `order_users`.`name` AS order_user_name
FROM (`order_albums`)
LEFT OUTER JOIN `orders` orders ON `orders`.`id` = `order_albums`.`order_id`
LEFT OUTER JOIN `users` order_users ON `order_users`.`id` = `orders`.`user_id`
GROUP BY `order_albums`.`order_id` ORDER BY `order_albums`.`id` DESC
So, I still think there's something wrong in the definition of your relationships.
Also, note the naming conventions. The model is called "User", the foreign key is called "user_id", the table is called "Users". Note the plural form![/quote]
1. i use $table definition so User model have $table = 'user'; ....
omg.. yes i have some result
Code:
SELECT `order_albums`.*, `orders`.`user_id` AS order_user_id, `orders`.`status` AS order_status, `order_users`.`id` AS order_user_id, `order_users`.`name` AS order_user_name
FROM (`order_albums`)
LEFT OUTER JOIN `orders` orders ON `orders`.`id` = `order_albums`.`order_id`
LEFT OUTER JOIN `users` order_users ON `order_users`.`id` = `orders`.`user_id`
GROUP BY `order_albums`.`order_id` ORDER BY `order_albums`.`id` DESC
because i dont want this
Code:
LEFT OUTER JOIN `users` order_users ON `order_users`.`id` = `orders`.`user_id`
understand me ?
![Smile Smile](https://forum.codeigniter.com/images/smilies/smile.png)
)
i want join USER with ORDER with foreign key . not with next new table - order_users
I do not understand or you ?
![Smile Smile](https://forum.codeigniter.com/images/smilies/smile.png)
))