class GdatastoreMapper::Relation
Attributes
association[RW]
klass[RW]
Public Class Methods
new(klass, association)
click to toggle source
# File lib/gdatastore_mapper/relation.rb, line 9 def initialize(klass, association) @klass = klass @association = association end
Public Instance Methods
create(attributes)
click to toggle source
# File lib/gdatastore_mapper/relation.rb, line 19 def create attributes belonging = create_belonging attributes update_owner belonging belonging end
new(attributes)
click to toggle source
# File lib/gdatastore_mapper/relation.rb, line 14 def new attributes belonging_attr = attributes.merge(@association.owner_attributes) @association.belonging_klass.new(belonging_attr) end
Private Instance Methods
create_belonging(attributes)
click to toggle source
# File lib/gdatastore_mapper/relation.rb, line 27 def create_belonging attributes belonging_attr = attributes.merge(@association.owner_attributes) @association.belonging_klass.create(belonging_attr) end
update_owner(belonging)
click to toggle source
# File lib/gdatastore_mapper/relation.rb, line 32 def update_owner belonging existing_ids = @association.owner.send(@association.belonging_id) existing_ids = [] if existing_ids.nil? owner_attr = {} owner_attr[@association.belonging_id] = (existing_ids << belonging.id) @association.owner.update(owner_attr) end