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 ActiveSupport::Concern

class_methods

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, #touch, #update, #update!, #update_attribute, #update_attribute!, #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
45
# File 'lib/neo4j/active_rel/persistence.rb', line 42

def concurrent_increment!(attribute, by = 1)
  query_rel = Neo4j::Session.query.match('()-[n]-()').where(n: {neo_id: neo_id})
  increment_by_query! query_rel, attribute, by
end

#create_methodObject



76
77
78
# File 'lib/neo4j/active_rel/persistence.rb', line 76

def create_method
  self.class.create_method
end

#create_modelObject



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

def create_model
  validate_node_classes!
  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

#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