Module: Neo4j::ActiveRel::Persistence

Extended by:
ActiveSupport::Concern
Includes:
Shared::Cypher::RelIdentifiers, Shared::Persistence
Included in:
Neo4j::ActiveRel
Defined in:
lib/neo4j/active_rel/persistence.rb,
lib/neo4j/active_rel/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:

  • name (Symbol, String)

    of the attribute to increment

  • amount (Integer, Float)

    to increment



42
43
44
# File 'lib/neo4j/active_rel/persistence.rb', line 42

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

#create_methodObject



92
93
94
# File 'lib/neo4j/active_rel/persistence.rb', line 92

def create_method
  self.class.create_method
end

#create_modelObject



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

def create_model
  validate_node_classes!
  validate_has_one_rel
  rel = _create_rel
  return self unless rel.respond_to?(:props)
  init_on_load(rel, from_node, to_node, @rel_type)
  true
end

#cypher_identifierObject



27
28
29
# File 'lib/neo4j/active_rel/persistence.rb', line 27

def cypher_identifier
  @cypher_identifier || :rel
end

#from_node_identifierObject



11
12
13
# File 'lib/neo4j/active_rel/persistence.rb', line 11

def from_node_identifier
  @from_node_identifier || :from_node
end

#from_node_identifier=(id) ⇒ Object



19
20
21
# File 'lib/neo4j/active_rel/persistence.rb', line 19

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

#query_as(var) ⇒ Object



61
62
63
64
65
# File 'lib/neo4j/active_rel/persistence.rb', line 61

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/neo4j/active_rel/persistence.rb', line 31

def save(*)
  create_or_update
end

#save!(*args) ⇒ Object



35
36
37
# File 'lib/neo4j/active_rel/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/neo4j/active_rel/persistence.rb', line 15

def to_node_identifier
  @to_node_identifier || :to_node
end

#to_node_identifier=(id) ⇒ Object



23
24
25
# File 'lib/neo4j/active_rel/persistence.rb', line 23

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

#validate_has_one_relObject



55
56
57
58
59
# File 'lib/neo4j/active_rel/persistence.rb', line 55

def validate_has_one_rel
  return unless Neo4j::Config[:enforce_has_one]
  to_node.validate_reverse_has_one_active_rel(self, :in, from_node) if to_node.persisted?
  from_node.validate_reverse_has_one_active_rel(self, :out, to_node) if from_node.persisted?
end