has_many :thought order ordering problems #1660

anyware opened this Issue Jun 12, 2011 · 5 comments

4 participants


My problem is:

A default_scope :order => "position ASC"

B has_many BJoinA
B has_many A :through BJoinA, :order => "BJoinA.position ASC"

I have A to ordered in a certain way.
and I have B's As ordered in a different way (though the join model).

But B.first.as does not return me As ordered by BJoinA position because the select include A's default_scope ordering first.

Is there a way to ignore default_scope (order) in has_many :through association?
Or should the join order be respected first?

the resulted select is:
SELECT "AS".* FROM "AS" INNER JOIN "B_AS" ON "AS".id = "B_AS".A_ID WHERE (("B_AS".B_ID = 3)) ORDER BY position ASC, B_AS.position ASC

I would like the B_AS.position AS to be the first condition

Using 3.0.4 or 3.0.7


@pixeltrix pixeltrix was assigned Jun 12, 2011
Ruby on Rails member

Please can you test using a 3.1 RC and let us know if the problem still exists?

Ruby on Rails member

Jon, yes it does - I was thinking of adding :reorder to the list of association options as a way of fixing it, but it's too late for 3.1. We can't change the behaviour either since it's been this way for quite a while.

Ruby on Rails member

+1 on adding :reorder. seems like the only solution. agree too late for 3.1

Ruby on Rails member

Is this still an issue @anyware? We're past 3.1 now. :)

Ruby on Rails member

It appears that, at the least, #2083 has superseded this issue. It's not even a bug, exactly, just a change in behavior that may make more sense. Therefore, I'm closing this in favor of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment