Skip to content

Instantly share code, notes, and snippets.

@Agowan
Created September 11, 2012 16:46
Show Gist options
  • Save Agowan/3699756 to your computer and use it in GitHub Desktop.
Save Agowan/3699756 to your computer and use it in GitHub Desktop.
Squeel bug report (duplicated "order by" when using default_scope inherited to a STI sub class)
# encoding: utf-8
gem 'sqlite3', '1.3.6'
gem 'activerecord', '3.2.8'
gem 'squeel', '1.0.11'
require 'active_record'
require 'squeel'
require 'squeel/version'
require 'logger'
puts "Active Record #{ActiveRecord::VERSION::STRING}"
puts "Squeel #{Squeel::VERSION}"
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
ActiveRecord::Schema.define do
create_table :cars do |t|
t.string :name
t.string :type
t.datetime :start_at
end
create_table :customers do |t|
t.string :name
t.string :type
t.datetime :start_at
end
end
class Car < ActiveRecord::Base
default_scope order( "start_at" )
end
class Truck < Car; end
class Customer < ActiveRecord::Base
default_scope order{ start_at.asc }
end
class Company < Customer; end
# When not using squeel the generated sql looks fine
Car.last
Truck.last
# When using squeel on the sti subclass
# the order by is dublicated
puts "======================================================================="
puts "# => \"'customers'.'start_at' DESC\" will be duplicated"
puts "======================================================================="
Customer.last
Company.last
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment