Module: Protobuf::ActiveRecord::NestedAttributes

Extended by:
ActiveSupport::Concern
Defined in:
lib/protobuf/active_record/nested_attributes.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#assign_nested_attributes_for_collection_association(association_name, attributes_collection) ⇒ Object

:nodoc:



32
33
34
35
36
37
38
39
40
41
# File 'lib/protobuf/active_record/nested_attributes.rb', line 32

def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
  if attributes_collection.first.is_a?(::Protobuf::Message)
    reflection = self.class._reflect_on_association(association_name)
    attributes_collection = attributes_collection.map do |attributes|
      reflection.klass.attributes_from_proto(attributes)
    end
  end

  super
end

#assign_nested_attributes_for_one_to_one_association(association_name, attributes) ⇒ Object

:nodoc:



44
45
46
47
48
49
50
51
# File 'lib/protobuf/active_record/nested_attributes.rb', line 44

def assign_nested_attributes_for_one_to_one_association(association_name, attributes)
  if attributes.is_a?(::Protobuf::Message)
    reflection = self.class._reflect_on_association(association_name)
    attributes = reflection.klass.attributes_from_proto(attributes)
  end

  super
end