module Redgraph::NodeModel::Persistence
Public Instance Methods
add_to_graph(allow_duplicates: true)
click to toggle source
Adds the node to the graph
-
allow_duplicates: if false it will create a node with the same type and properties only if
not present
# File lib/redgraph/node_model/persistence.rb, line 9 def add_to_graph(allow_duplicates: true) raise MissingGraphError unless graph item = allow_duplicates ? graph.add_node(to_node) : graph.merge_node(to_node) self.id = item.id self end
destroy()
click to toggle source
Deletes the record from the graph
# File lib/redgraph/node_model/persistence.rb, line 40 def destroy @destroyed = true if graph.destroy_node(self) self else false end end
destroyed?()
click to toggle source
Returns true if this object has been destroyed, otherwise returns false.
# File lib/redgraph/node_model/persistence.rb, line 51 def destroyed? !!@destroyed end
persisted?()
click to toggle source
# File lib/redgraph/node_model/persistence.rb, line 27 def persisted? id.present? end
reload()
click to toggle source
# File lib/redgraph/node_model/persistence.rb, line 31 def reload item = self.class.find(id) @label = item.label assign_attributes(item.attributes) self end
save()
click to toggle source
Creates a new record or updates the existing
# File lib/redgraph/node_model/persistence.rb, line 18 def save if persisted? item = graph.update_node(to_node) self.class.reify_from_node(item) else add_to_graph end end