Created
February 15, 2013 02:28
-
-
Save hughdavenport/4958157 to your computer and use it in GitHub Desktop.
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
gem 'activerecord' | |
require 'active_record' | |
require 'logger' | |
puts "Active Record #{ActiveRecord::VERSION::STRING}" | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'sqlite3', | |
:database => ':memory:' | |
) | |
ActiveRecord::Base.logger = Logger.new(STDERR) | |
ActiveRecord::Schema.define do | |
create_table :t1s, :force => true do |t| | |
t.boolean :flag | |
end | |
create_table :t2s, :force => true do |t| | |
t.integer :t1_id | |
end | |
end | |
class T1 < ActiveRecord::Base | |
default_scope where(:flag => true) | |
has_many :t2 | |
attr_accessor :active | |
end | |
class T2 < ActiveRecord::Base | |
belongs_to :t1 | |
end | |
t1_false = T1.create(:flag => false) | |
t1_true = T1.create(:flag => true) | |
t2_false = T2.create(:t1 => t1_false) | |
t2_true = T2.create(:t1 => t1_true) | |
ret = T1.all | |
ret.each do |row| | |
if (!row.flag) then | |
p "#{row.id} BAD (T1 select)" | |
end | |
end | |
ret = T2.includes(:t1) | |
ret.each do |row| | |
if (!row.t1.nil? and !row.t1.flag) then | |
p "#{row.t1.id} BAD (T2 select + includes T1)" | |
end | |
end | |
ret = T2.joins(:t1) | |
ret.each do |row| | |
if (!row.t1.nil? and !row.t1.flag) then | |
p "#{row.t1.id} BAD (T2 select + joins T1)" | |
end | |
end | |
# Bug lies here... | |
ret = T2.includes(:t1).joins(:t1) | |
ret.each do |row| | |
if (!row.t1.nil? and !row.t1.flag) then | |
p "#{row.t1.id} BAD (T2 select + includes T1 + joins T1)" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment