The AR documentation states: You can use eager loading on multiple associations from the same table, but you cannot use those associations in orders and conditions as there is currently not any way to disambiguate them. Has anyone worked up a patch for this? I'm thinking that it would be useful to state, for instance: has_many :deployments, :class_name => 'Deployment', :order => "_table_.start_at" Then, AR would automatically swap out the "_table_" string for the created-on-the-fly table alias. This would allow you, for instance, to refer to the same table multiple times with conditions and order clauses. Has anyone thought of another solution to this problem? Would this be a feasible way to address the problem? I'd be willing to work on a patch if necessary. Thanks, Norman Elton
on 2008-05-02 05:21
on 2008-05-02 05:26
There's some work under way for the next release of rails ( post 2.1 ) to completely rejig all the query generation for precisely these kind of issues. I think it'll probably be easier to hold fire till then. Cheers Koz
on 2008-05-02 05:30
Sounds good. If there's anything I can do, feel free to put me in touch with whoever's in charge. Norman
on 2008-05-02 12:13
On 2 May 2008, at 04:29, Norm wrote: > > Sounds good. If there's anything I can do, feel free to put me in > touch with whoever's in charge. > It's also worth noting that independantly eager loading has changed in 2.1 (though the old mechanism is still there). I vaguely remember that if it's a conditions thing then you can do something like :conditions => '#{"#{aliased_table_name}." rescue ""}foo = 123' Fred
on 2008-05-02 15:02
> It's also worth noting that independantly eager loading has changed in > 2.1 (though the old mechanism is still there). > I vaguely remember that if it's a conditions thing then you can do > something like :conditions => '#{"#{aliased_table_name}." rescue > ""}foo = 123' Fred, Thanks for your note. Doing a little research, I found the webpage that you referenced a few days ago (didn't see it before, sorry). I'll trying moving to edge and see how things work there. Norman