Sha256: 1260a912308c4044867996fafe1d884ff034d20932518fe3cb17c50d1e147f95

Contents?: true

Size: 739 Bytes

Versions: 1

Compression:

Stored size: 739 Bytes

Contents

module Para
  module AttributeField
    class NestedOneField < AttributeField::BelongsToField
      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

1 entries across 1 versions & 1 rubygems

Version Path
para-0.4.0 lib/para/attribute_field/nested_one.rb