Я только что обновился с Rails 4.0.2 до Rails 4.1.1 и наблюдаю странное поведение при попытке использовать includes
в запросе ActiveRecord. Я работаю в 64-битной среде разработки Windows 7. У меня определены следующие модели:
class Article < ActiveRecord::Base
belongs_to :intro_image, :class_name => "UploadedFile"
belongs_to :user
end
class User < ActiveRecord::Base
has_many :articles
end
class UploadedFile < ActiveRecord::Base
has_many :articles, :foreign_key => :intro_image_id, :dependent => :nullify
end
Когда я открываю консоль и выполняю следующие команды, они работают так, как ожидалось.
Article.count # => 19 records
Article.includes(:user) # => 19 records returned and I see the load call on the User table
Однако, выполнив следующую команду,
Article.includes(:intro_image)
генерирует следующий вывод в консоли,
Article Load (1.0ms) SELECT `articles`.* FROM `articles`
UploadedFile Load (1.0ms) SELECT `uploaded_files`.* FROM `uploaded_files` WHERE `uploaded_files`.`id` IN (3, 4, 6, 8, 0, 9, 13, 15, 40, 48, 49, 50, 51, 56, 55, 53, 54, 52)
(Object doesn't support #inspect)
Почему этот вызов генерирует сообщение Object doesn't support #inspect
? Кроме того, если я выполню следующую команду:
Article.includes(:intro_image).to_a
Я получаю следующую трассировку стека
NoMethodError: undefined method `each' for nil:NilClass
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader/association.rb:87:in `block in associated_records_by_owner'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader/association.rb:86:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader/association.rb:86:in `associated_records_by_owner'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader/singular_association.rb:9:in `preload'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader/association.rb:20:in `run'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader.rb:136:in `block (2 levels) in preloaders_for_one'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader.rb:134:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader.rb:134:in `map'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader.rb:134:in `block in preloaders_for_one'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader.rb:133:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader.rb:133:in `flat_map'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader.rb:133:in `preloaders_for_one'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader.rb:106:in `preloaders_on'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bullet-4.9.0/lib/bullet/active_record41.rb:34:in `preloaders_on'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader.rb:94:in `block in preload'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/associations/preloader.rb:93:in `each'
... 5 levels...
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/relation.rb:487:in `load'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/relation.rb:231:in `to_a'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bullet-4.9.0/lib/bullet/active_record41.rb:10:in `to_a'
from (irb):13
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from C:/Users/Tom/Documents/dev/site/site_source/bin/rails:4:in `require'
from C:/Users/Tom/Documents/dev/site/site_source/bin/rails:4:in `<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/ruby-debug-ide-0.4.23.beta1/lib/ruby-debug-ide.rb:86:in `debug_load'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/ruby-debug-ide-0.4.23.beta1/lib/ruby-debug-ide.rb:86:in `debug_program'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/ruby-debug-ide-0.4.23.beta1/bin/rdebug-ide:110:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'