Module: Neo4j::Rails::RelationshipPersistence
- Extended by:
- TxMethods
- Included in:
- Relationship
- Defined in:
- lib/neo4j/rails/relationship_persistence.rb
Instance Method Summary (collapse)
- - (Object) create
-
- (Object) end_node
Returns the end node which can be unpersisted.
- - (Object) freeze_if_deleted
-
- (Object) initialize(*args)
Initialize a Node with a set of properties (or empty if nothing is passed).
- - (Object) other_node(node)
-
- (Symbol) rel_type
The relationship type.
-
- (Object) reload(options = nil)
Reload the object from the DB.
- - (Object) reload_from_database
-
- (Object) start_node
Returns the start node which can be unpersisted.
Methods included from TxMethods
Instance Method Details
- (Object) create
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/neo4j/rails/relationship_persistence.rb', line 20 def create # prevent calling create twice @_start_node.add_unpersisted_outgoing_rel(rel_type, self) @_end_node.add_unpersisted_incoming_rel(rel_type, self) return unless _persist_node(@_start_node) && _persist_node(@_end_node) java_rel = Neo4j::Relationship.new(rel_type, start_node, end_node) init_on_load(java_rel) Neo4j::IdentityMap.add(java_rel, self) init_on_create @_start_node.rm_unpersisted_outgoing_rel(rel_type, self) @_end_node.rm_unpersisted_incoming_rel(rel_type, self) true end |
- (Object) end_node
Returns the end node which can be unpersisted
60 61 62 |
# File 'lib/neo4j/rails/relationship_persistence.rb', line 60 def end_node @_end_node ||= _java_rel && _java_rel.end_node.wrapper end |
- (Object) freeze_if_deleted
76 77 78 79 80 81 82 83 84 |
# File 'lib/neo4j/rails/relationship_persistence.rb', line 76 def freeze_if_deleted unless new_record? Neo4j::IdentityMap.remove_rel_by_id(neo_id) unless self.class.load_entity(neo_id) set_deleted_properties freeze end end end |
- (Object) initialize(*args)
Initialize a Node with a set of properties (or empty if nothing is passed)
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/neo4j/rails/relationship_persistence.rb', line 7 def initialize(*args) return initialize_attributes(nil) if args.size < 3 # then we have been loaded type, start_node, end_node, attributes = args @_rel_type = type.to_sym raise "Unknown type" unless type raise "Unknown start_node" unless start_node raise "Unknown end_node" unless end_node self.start_node = start_node self.end_node = end_node initialize_attributes(attributes) end |
- (Object) other_node(node)
43 44 45 46 47 48 49 50 |
# File 'lib/neo4j/rails/relationship_persistence.rb', line 43 def other_node(node) n = if persisted? _java_rel._other_node(node._java_entity) else @_start_node == node ? @_end_node : @_start_node end n && n.wrapper end |
- (Symbol) rel_type
The relationship type
38 39 40 |
# File 'lib/neo4j/rails/relationship_persistence.rb', line 38 def rel_type new_record? ? @_rel_type : _java_entity.rel_type.to_sym end |
- (Object) reload(options = nil)
Reload the object from the DB
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/neo4j/rails/relationship_persistence.rb', line 65 def reload( = nil) raise "Can't reload a none persisted node" if new_record? clear_changes reset_attributes unless reload_from_database set_deleted_properties freeze end self end |
- (Object) reload_from_database
86 87 88 89 90 91 92 |
# File 'lib/neo4j/rails/relationship_persistence.rb', line 86 def reload_from_database Neo4j::IdentityMap.remove_rel_by_id(id) if persisted? if reloaded = self.class.load_entity(id) send(:attributes=, reloaded.attributes, false) end reloaded end |
- (Object) start_node
Returns the start node which can be unpersisted
54 55 56 |
# File 'lib/neo4j/rails/relationship_persistence.rb', line 54 def start_node @_start_node ||= _java_rel && _java_rel.start_node.wrapper end |