lib/mongoid/association/embedded/embedded_in/buildable.rb in mongoid-7.0.13 vs lib/mongoid/association/embedded/embedded_in/buildable.rb in mongoid-7.1.0.rc0

- old
+ new

@@ -1,5 +1,8 @@ +# frozen_string_literal: true +# encoding: utf-8 + module Mongoid module Association module Embedded class EmbeddedIn @@ -16,15 +19,18 @@ # Builder.new(meta, attrs).build # # @param [ Object ] base The object. # @param [ Object ] object The parent hash or document. # @param [ String ] type Not used in this context. + # @param [ Hash ] selected_fields Fields which were retrieved via + # #only. If selected_fields are specified, fields not listed in it + # will not be accessible in the built document. # # @return [ Document ] A single document. - def build(base, object, type = nil) + def build(base, object, type = nil, selected_fields = nil) return object unless object.is_a?(Hash) if _loading? - Factory.from_db(klass, object) + Factory.from_db(klass, object, nil, selected_fields) else Factory.build(klass, object) end end end