Bug Report #4455
Cannot join using ORM
| Status: | Closed | Start date: | 02/21/2012 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | - | |||
| Target version: | Kohana v3.x - v3.2.1 | |||
| Resolution: | invalid | Points: | 1 |
Description
For example, there is 2 tables
users and notes,
user has many notes.
And when i need to join the table
ORM::factory('note')
>join('users')>on('users.id', '=', 'notes.user_id')
->find_all();
The errors
Unknown column 'notes.user_id' in 'on clause' [ SELECT `note`.* FROM `notes` AS `note` JOIN `users` ON (`users`.`id` = `notes`.`user_id`) ]
I think the problem is ORM trying to rename notes AS note.
Works perfectly on 3.2 below
I am suprised this hasn't been reported? Is this expected?
History
Updated by Kemal Delalic 3 months ago
It's the expected behavior, ORM uses the singular alias when building queries (since 3.2) - invalid ticket
Updated by dexcell - 3 months ago
Can you elaborate how to do it correctly in 3.2? Because there is no migration guide for ORM as far as i can recall.
Thank you
Updated by Kemal Delalic 3 months ago
dexcell - wrote:
Can you elaborate how to do it correctly in 3.2? Because there is no migration guide for ORM as far as i can recall.
Thank you
Sure;
ORM::factory('note')
->join('users')
->on('users.id', '=', 'note.user_id')
->find_all();
Updated by Isaiah DeRose-Wilson 3 months ago
- Project changed from Kohana v3.x to ORM
- Category deleted (
Modules:ORM) - Status changed from New to Closed
- Assignee set to Isaiah DeRose-Wilson
Updated by Isaiah DeRose-Wilson 3 months ago
- Priority changed from Urgent to Normal
- Resolution set to invalid
Updated by dexcell - 3 months ago
Thanks Kemal,
Any reason / merit why it's changed this way?
Because i imagine this would become a mess in the codes because you have to remember when you use plural and singular name when joining the tables, since there is a high percentage an application would use 3-4 tables join.
Thank you