Module: CustomFieldsManyExtension

Defined in:
lib/custom_fields/extensions/mongoid/association/referenced/has_many.rb

Overview

end

end

end

Instance Method Summary collapse

Instance Method Details

#build(attributes = {}, type = nil) ⇒ Object Also known as: new



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/custom_fields/extensions/mongoid/association/referenced/has_many.rb', line 35

def build(attributes = {}, type = nil)
  if _base.respond_to?(:custom_fields_for?) && _base.custom_fields_for?(association.name)
    # all the information about how to build the custom class are stored here
    recipe = _base.custom_fields_recipe_for(association.name)
    attributes ||= {}
    attributes.merge!(custom_fields_recipe: recipe)
    # build the class with custom_fields for the first time
    type = association.klass.klass_with_custom_fields(recipe)
  end
  super(attributes, type)
end