-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
Le't s have a has_one relation with autosave: true and validate: false.
class Foo
include Mongoid::Document
has_one :bar, autosave: true, validate: false
end
class Bar
include Mongoid::Document
belongs_to :foo
end
>> foo = Foo.first
foo = Foo.first
MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=foos selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.4294ms)
#<Foo _id: 512c4ba25b9e0528b5000002, >
>> foo.save
MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=bars selector={"$query"=>
, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.8771ms)
true
So for some reason it makes a query for bar. But we have validate: false, and as the relation hasn't been loaded, there's obviously nothing to save in the bar object.