Module: Alula::RelationshipAttributes::InstanceMethods

Defined in:
lib/alula/relationship_attributes.rb

Instance Method Summary collapse

Instance Method Details

#add_model_to_relationship(model) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/alula/relationship_attributes.rb', line 77

def add_model_to_relationship(model)        
  relation = get_relationship(model.get_type)
  unless relation
    raise "Unknown model relationship #{model.get_type} for model #{self.class}"
  end

  if relation[:cardinality] == 'To-one'
    self.send("#{relation[:name]}=", model)

  elsif relation[:cardinality] == 'To-many'
    if self.send(relation[:name]).nil?
      list = Alula::ListObject.new(model.class)
      list << model
    end

    self.send("#{relation[:name]}<<", model)
  else
    raise "Unknown relationship cardinality for relationship #{relation.inspect}"
  end
end

#check_relationship!(relationship) ⇒ Object



102
103
104
# File 'lib/alula/relationship_attributes.rb', line 102

def check_relationship!(relationship)
  self.class.check_relationship!(relationship)
end

#get_relationship(name) ⇒ Object



73
74
75
# File 'lib/alula/relationship_attributes.rb', line 73

def get_relationship(name)
  self.class.get_relationship(name)
end

#get_relationshipsObject



69
70
71
# File 'lib/alula/relationship_attributes.rb', line 69

def get_relationships
  self.class.get_relationships
end

#relationship_exists?(relationship) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/alula/relationship_attributes.rb', line 98

def relationship_exists?(relationship)
  self.class.relationship_exists?(relationship)
end