Module: ActiveGraph::Relationship::Persistence

Extended by:
ActiveSupport::Concern
Includes:
Shared::Cypher::RelIdentifiers, Shared::Persistence
Included in:
ActiveGraph::Relationship
Defined in:
lib/active_graph/relationship/persistence.rb,
lib/active_graph/relationship/persistence/query_factory.rb

Defined Under Namespace

Modules: ClassMethods Classes: ModelClassInvalidError, QueryFactory, RelCreateFailedError, RelInvalidError

Instance Method Summary collapse

Methods included from Shared::Persistence

#apply_default_values, #cache_key, #create_or_update, #destroy, #destroyed?, #exist?, #freeze, #frozen?, #increment, #increment!, #new_record?, #persisted?, #props, #props_for_create, #props_for_persistence, #props_for_update, #reload, #reload_from_database, #skip_update?, #touch, #update, #update!, #update_attribute, #update_attribute!, #update_db_properties, #update_db_property, #update_model

Instance Method Details

#concurrent_increment!(attribute, by = 1) ⇒ Object

Increments concurrently a numeric attribute by a centain amount

Parameters:

  • attribute (Symbol, String)

    name of the attribute to increment

  • by (Integer, Float) (defaults to: 1)

    amount to increment


42
43
44
# File 'lib/active_graph/relationship/persistence.rb', line 42

def concurrent_increment!(attribute, by = 1)
  increment_by_query! query_as(:r), attribute, by, :r
end

#create_methodObject


91
92
93
# File 'lib/active_graph/relationship/persistence.rb', line 91

def create_method
  self.class.create_method
end

#create_modelObject


46
47
48
49
50
51
52
53
# File 'lib/active_graph/relationship/persistence.rb', line 46

def create_model
  validate_node_classes!
  delete_has_one_rel
  rel = _create_rel
  return self unless rel.respond_to?(:properties)
  init_on_load(rel, from_node, to_node, @type)
  true
end

#cypher_identifierObject


27
28
29
# File 'lib/active_graph/relationship/persistence.rb', line 27

def cypher_identifier
  @cypher_identifier || :rel
end

#delete_has_one_relObject


55
56
57
58
# File 'lib/active_graph/relationship/persistence.rb', line 55

def delete_has_one_rel
  to_node.delete_reverse_has_one_relationship(self, :in, from_node) if to_node.persisted?
  from_node.delete_reverse_has_one_relationship(self, :out, to_node) if from_node.persisted?
end

#from_node_identifierObject


11
12
13
# File 'lib/active_graph/relationship/persistence.rb', line 11

def from_node_identifier
  @from_node_identifier || :from_node
end

#from_node_identifier=(id) ⇒ Object


19
20
21
# File 'lib/active_graph/relationship/persistence.rb', line 19

def from_node_identifier=(id)
  @from_node_identifier = id.to_sym
end

#query_as(var) ⇒ Object


60
61
62
63
64
# File 'lib/active_graph/relationship/persistence.rb', line 60

def query_as(var)
  # This should query based on the nodes, not the rel neo_id, I think
  # Also, picky point: Should the var be `n`?
  self.class.query_as(neo_id, var)
end

#saveObject


31
32
33
# File 'lib/active_graph/relationship/persistence.rb', line 31

def save(*)
  create_or_update
end

#save!(*args) ⇒ Object


35
36
37
# File 'lib/active_graph/relationship/persistence.rb', line 35

def save!(*args)
  save(*args) or fail(RelInvalidError, inspect) # rubocop:disable Style/AndOr
end

#to_node_identifierObject


15
16
17
# File 'lib/active_graph/relationship/persistence.rb', line 15

def to_node_identifier
  @to_node_identifier || :to_node
end

#to_node_identifier=(id) ⇒ Object


23
24
25
# File 'lib/active_graph/relationship/persistence.rb', line 23

def to_node_identifier=(id)
  @to_node_identifier = id.to_sym
end