Created issue
https://github.com/mongoid/mongoid/issues/1297
I would like to help with this fix, but I am new to the Mongoid
internals, so I debugged the code a few times and came up with the
following patch:
module Mongoid
module Relations
module Accessors
def build(name, object, metadata, options = {})
relation = (options[:loading] == true) && persisted? ?
create_relation(object, metadata, options[:loading]) : nil
set_relation(name, relation)
end
end
end
end
Does this make sense? Or is it more suitable to put it somewhere else?
The original build method looks like:
def build(name, object, metadata, options = {})
relation = create_relation(object, metadata,
options[:loading])
set_relation(name, relation)
end