We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This might be an arel bug rather than a baby_squeel bug, apologies if so!
arel
baby_squeel
When using Active Record 4,
Foo.reorder(:x).last
appears to not be equivalent to
Foo.reordering { x }.last
but it is with Active Record 5.
Specifically, it appears that we don't get a DESC in the resulting query in AR 4:
DESC
Foo Load (0.1ms) SELECT "foos".* FROM "foos" ORDER BY "foos"."x" LIMIT 1
whereas we do in AR 5:
Foo Load (0.1ms) SELECT "foos".* FROM "foos" ORDER BY "foos"."x" DESC LIMIT ? [["LIMIT", 1]]
N.B. adding an explicit direction does work in both AR versions:
Foo.reorder('x ASC').last == Foo.reordering { x.asc }.last
require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'activerecord', '= 4.2.10' # breaks # gem 'activerecord', '= 5.1.4' # works gem 'sqlite3' gem 'baby_squeel', github: 'rzane/baby_squeel' end require 'active_record' require 'minitest/autorun' require 'logger' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Schema.define do create_table :foos do |t| t.integer :x end end class Foo < ActiveRecord::Base end ActiveRecord::Base.logger = Logger.new(STDOUT) class BabySqueelTest < Minitest::Spec it 'works' do one = Foo.create(x: 1) two = Foo.create(x: 2) puts "reorder" assert_equal one, Foo.reorder('x ASC').first assert_equal one, Foo.reorder('x DESC').last assert_equal one, Foo.reorder('x').first assert_equal two, Foo.reorder('x ASC').last assert_equal two, Foo.reorder('x DESC').first assert_equal two, Foo.reorder('x').last puts "reordering" assert_equal one, Foo.reordering { x.asc }.first assert_equal one, Foo.reordering { x.desc }.last assert_equal one, Foo.reordering { x }.first assert_equal two, Foo.reordering { x.asc }.last assert_equal two, Foo.reordering { x.desc }.first assert_equal two, Foo.reordering { x }.last # Doesn't work with AR 4 end end
The text was updated successfully, but these errors were encountered:
Just to clarify, this not only affects reordering but also ordering.
Sorry, something went wrong.
Disable order compatible mode for ActiveRecord < 5
cbdc012
There is a bug with order and last: rzane#84
70eb4f5
9a4a711
bc13738
No branches or pull requests
This might be an
arel
bug rather than ababy_squeel
bug, apologies if so!Issue
When using Active Record 4,
appears to not be equivalent to
but it is with Active Record 5.
Specifically, it appears that we don't get a
DESC
in the resulting query in AR 4:whereas we do in AR 5:
N.B. adding an explicit direction does work in both AR versions:
Reproduction
The text was updated successfully, but these errors were encountered: