Module: StoreModel::NestedAttributes::ClassMethods

Defined in:
lib/store_model/nested_attributes.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#accepts_nested_attributes_for(*associations) ⇒ Object

Enables handling of nested StoreModel::Model attributes

Parameters:

  • associations (Array)

    list of associations to define attributes



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/store_model/nested_attributes.rb', line 14

def accepts_nested_attributes_for(*associations)
  associations.each do |association|
    case attribute_types[association.to_s]
    when Types::JsonType
      alias_method "#{association}_attributes=", "#{association}="
    when Types::ArrayType
      define_method "#{association}_attributes=" do |attributes|
        assign_nested_attributes_for_collection_association(association, attributes)
      end
    end
  end
end