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
D, [2010-10-13T12:06:16.254575 #16142] DEBUG -- : SQL (0.3ms) select sqlite_version(*) | |
D, [2010-10-13T12:06:16.255374 #16142] DEBUG -- : SQL (0.5ms) CREATE TABLE "widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "accessory_id" integer) | |
D, [2010-10-13T12:06:16.255771 #16142] DEBUG -- : SQL (0.1ms) CREATE TABLE "accessories" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) | |
D, [2010-10-13T12:06:16.271467 #16142] DEBUG -- : SQL (0.1ms) SELECT name | |
FROM sqlite_master | |
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | |
D, [2010-10-13T12:06:16.275491 #16142] DEBUG -- : SQL (0.1ms) INSERT INTO "accessories" VALUES(NULL) | |
D, [2010-10-13T12:06:16.281336 #16142] DEBUG -- : SQL (0.1ms) INSERT INTO "widgets" ("accessory_id") VALUES (1) | |
D, [2010-10-13T12:06:16.286909 #16142] DEBUG -- : 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', '3.0.0' | |
require 'active_record' | |
require 'logger' | |
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
/Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/association_preload.rb:324:in `send': missing attribute: accessory_id (ActiveModel::MissingAttributeError) | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/association_preload.rb:324:in `preload_belongs_to_association' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/association_preload.rb:323:in `each' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/association_preload.rb:323:in `preload_belongs_to_association' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/association_preload.rb:121:in `send' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/association_preload.rb:121:in `preload_one_association' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-3.0.0/lib/active_support/ordered_hash.rb:126:in `each' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-3.0.0/lib/active_support/ordered_hash.rb:126:in `each' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/association_preload.rb:115:in `preload_one_association' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/association_preload.rb:92:in `preload_associations' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/relation.rb:68:in `send' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/relation.rb:68:in `to_a' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/relation.rb:68:in `each' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/relation.rb:68:in `to_a' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/relation/finder_methods.rb:333:in `find_first' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/relation/finder_methods.rb:122:in `first' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/relation/finder_methods.rb:180:in `exists?' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/relation/finder_methods.rb:176:in `exists?' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/base.rb:439:in `__send__' | |
from /Users/davidyip/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-3.0.0/lib/active_record/base.rb:439:in `exists?' | |
from exists_with_scope.rb:32 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment