Class: Holistic::Database::Relation

Inherits:
Set
  • Object
show all
Defined in:
lib/holistic/database/relation.rb

Instance Method Summary collapse

Constructor Details

#initialize(node:, name:, inverse_of:) ⇒ Relation

Returns a new instance of Relation.



4
5
6
7
8
9
10
# File 'lib/holistic/database/relation.rb', line 4

def initialize(node:, name:, inverse_of:)
  @node = node
  @name = name
  @inverse_of = inverse_of

  super()
end

Instance Method Details

#add!(related_node) ⇒ Object



12
13
14
15
# File 'lib/holistic/database/relation.rb', line 12

def add!(related_node)
  @node.relations[@name].add(related_node)
  related_node.relations[@inverse_of].add(@node)
end

#delete!(related_node) ⇒ Object



17
18
19
20
# File 'lib/holistic/database/relation.rb', line 17

def delete!(related_node)
  @node.relations[@name].delete(related_node)
  related_node.relations[@inverse_of].delete(@node)
end