Sha256: 1488f1c3fd124de8e9a881dd08b4bbce97d8a45e4f724a3372ae6747498e1056

Contents?: true

Size: 773 Bytes

Versions: 9

Compression:

Stored size: 773 Bytes

Contents

module Para
  module AttributeField
    class NestedManyField < AttributeField::HasManyField
      register :nested_many, self

      def parse_input(params)
        if (nested_attributes = params[nested_attributes_key])
          nested_attributes.each do |index, attributes|
            nested_model_mappings.fields.each do |field|
              field.parse_input(attributes)
            end

            params[nested_attributes_key][index] = attributes
          end
        else
          super(params)
        end
      end

      def nested_model_mappings
        @nested_model_mappings ||= AttributeFieldMappings.new(reflection.klass)
      end

      def nested_attributes_key
        @nested_attributes_key ||= :"#{ name }_attributes"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
para-0.6.9 lib/para/attribute_field/nested_many.rb
para-0.6.8 lib/para/attribute_field/nested_many.rb
para-0.6.7 lib/para/attribute_field/nested_many.rb
para-0.6.3 lib/para/attribute_field/nested_many.rb
para-0.6.2 lib/para/attribute_field/nested_many.rb
para-0.5.4 lib/para/attribute_field/nested_many.rb
para-0.5.3 lib/para/attribute_field/nested_many.rb
para-0.5.1 lib/para/attribute_field/nested_many.rb
para-0.5.0 lib/para/attribute_field/nested_many.rb