-
-
Save railscard/4ab5d5996bd867c08ec0 to your computer and use it in GitHub Desktop.
Rails 4 unscope bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bar < ActiveRecord::Base | |
default_scope -> { order(:name) } | |
has_many :foos, through: :foo_bars | |
has_many :foo_bars | |
end | |
class Foo < ActiveRecord::Base | |
has_many :bars, -> { unscope(:order).order('foo_bars.sort') }, through: :foo_bars | |
has_many :foo_bars | |
end | |
Foo.first.bars.to_sql | |
# Rails 4.0.0 | |
# => SELECT "bars".* FROM "bars" INNER JOIN "foo_bars" ON "bars"."id" = "foo_bars"."bar_id" WHERE "foo_bars"."foo_id" = ? ORDER BY "bars"."name" ASC, foo_bars.sort | |
# Rails 4.1.0.beta (master) | |
# => SELECT "bars".* FROM "bars" INNER JOIN "foo_bars" ON "bars"."id" = "foo_bars"."bar_id" WHERE "foo_bars"."foo_id" = ? ORDER BY foo_bars.sort" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment