Created
October 13, 2010 16:43
-
-
Save hannahwhy/624421 to your computer and use it in GitHub Desktop.
exists? with default_scope error (AR >= 2.3.9)
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
# Logfile created on Wed Oct 13 11:50:35 -0500 2010 by logger.rb/22285 | |
SQL (0.3ms) select sqlite_version(*) | |
SQL (0.5ms) CREATE TABLE "widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "accessory_id" integer) | |
SQL (0.1ms) CREATE TABLE "accessories" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) | |
Accessory Create (0.1ms) INSERT INTO accessories VALUES(NULL) | |
Widget Create (0.1ms) INSERT INTO "widgets" ("accessory_id") VALUES(1) | |
Widget Load (0.1ms) SELECT "widgets".id FROM "widgets" WHERE ("widgets"."accessory_id" = 1) LIMIT 1 |
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', '2.3.9' | |
require 'active_record' | |
require 'pp' | |
ActiveRecord::Base.logger = Logger.new('exists_with_scope.log') | |
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:') | |
ActiveRecord::Base.connection.create_table :widgets do |t| | |
t.references :accessory | |
end | |
ActiveRecord::Base.connection.create_table :accessories do |t| | |
end | |
class Widget < ActiveRecord::Base | |
belongs_to :accessory | |
default_scope :include => :accessory | |
end | |
class Accessory < ActiveRecord::Base | |
end | |
a1 = Accessory.create | |
Widget.create(:accessory_id => a1.id) | |
pp Widget.columns.map(&:name) | |
puts Widget.exists?(:accessory_id => a1) # should print "true" |
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
["id", "accessory_id"] | |
/Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:320:in `send': missing attribute: accessory_id (ActiveRecord::MissingAttributeError) | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:320:in `preload_belongs_to_association' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:319:in `each' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:319:in `preload_belongs_to_association' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:120:in `send' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:120:in `preload_one_association' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.9/lib/active_support/ordered_hash.rb:115:in `each' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.9/lib/active_support/ordered_hash.rb:115:in `each' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:114:in `preload_one_association' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:91:in `preload_associations' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:90:in `preload_associations' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:90:in `each' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/association_preload.rb:90:in `preload_associations' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/base.rb:1584:in `find_every' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/base.rb:1539:in `find_initial' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.9/lib/active_record/base.rb:696:in `exists?' | |
from exists_with_scope.rb:30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment