-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Hi, this doesn't seem right:
#!/usr/bin/env ruby
require 'mongoid'
Mongoid.configure do |config|
config.connect_to "mongoid_test"
end
class A
include Mongoid::Document
field :a, type: String
field :b, type: String
end
class B
include Mongoid::Document
field :c, type: String, default: 'c has been initialized'
end
puts B.new.inspect
A.delete_all
A.create(a: 'a', b: 'b')
A.only(:a).each do |a|
puts B.new.inspect
end
Output:
$./test_only.rb
#<B _id: 5048f28f66d9f1e55a000001, _type: nil, c: "c has been initialized">
#<B _id: , _type: nil, c: nil>
I've been bitten by this again and again. I don't think anyone would expect the call to A.only() to affect B.new executed inside that block. Or any other mongoid method called on anything except maybe the yielded a object.