Skip to content

Instantly share code, notes, and snippets.

@hughdavenport
Created February 24, 2013 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughdavenport/5025300 to your computer and use it in GitHub Desktop.
Save hughdavenport/5025300 to your computer and use it in GitHub Desktop.
--- default_scope.rb 2013-02-15 15:25:03.884271576 +1300
+++ no_scope.rb 2013-02-25 08:50:18.150799882 +1300
@@ -21,7 +21,6 @@
end
class T1 < ActiveRecord::Base
- default_scope where(:flag => true)
has_many :t2
attr_accessor :active
end
@@ -36,21 +35,21 @@
t2_false = T2.create(:t1 => t1_false)
t2_true = T2.create(:t1 => t1_true)
-ret = T1.all
+ret = T1.where("t1s.flag" => true).all
ret.each do |row|
if (!row.flag) then
p "#{row.id} BAD (T1 select)"
end
end
-ret = T2.includes(:t1)
+ret = T2.where("t1s.flag" => true).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 = T2.where("t1s.flag" => true).joins(:t1)
ret.each do |row|
if (!row.t1.nil? and !row.t1.flag) then
p "#{row.t1.id} BAD (T2 select + joins T1)"
@@ -58,7 +57,7 @@
end
# Bug lies here...
-ret = T2.includes(:t1).joins(:t1)
+ret = T2.where("t1s.flag" => true).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)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment