Forum: Rails-core (closed, excessive spam) Patch needed for AR multiple associations on same table?

6ec7697ec27284826a651f7a603d1825?d=identicon&s=25 Norman Elton (normelton)
on 2008-05-02 05:21
(Received via mailing list)
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
Efa76b164a7de4a5730e4fa397cc4425?d=identicon&s=25 Michael Koziarski (Guest)
on 2008-05-02 05:26
(Received via mailing list)
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
6ec7697ec27284826a651f7a603d1825?d=identicon&s=25 Norman Elton (normelton)
on 2008-05-02 05:30
(Received via mailing list)
Sounds good. If there's anything I can do, feel free to put me in
touch with whoever's in charge.

Norman
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-05-02 12:13
(Received via mailing list)
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
6ec7697ec27284826a651f7a603d1825?d=identicon&s=25 Norman Elton (normelton)
on 2008-05-02 15:02
(Received via mailing list)
> 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
This topic is locked and can not be replied to.