Sha256: da38293b0413ce2422200f0a92f0efbd9ea1b640767c3106dc9ba32b143cb294
Contents?: true
Size: 1.84 KB
Versions: 1
Compression:
Stored size: 1.84 KB
Contents
module Neo4j::ActiveNode module Persistence extend ActiveSupport::Concern include Neo4j::Shared::Persistence # Creates a model with values matching those of the instance attributes and returns its id. # @private # @return true def create_model(*) create_magic_properties set_timestamps create_magic_properties properties = convert_properties_to :db, props node = _create_node(properties) init_on_load(node, node.props) send_props(@relationship_props) if @relationship_props @relationship_props = nil # Neo4j::IdentityMap.add(node, self) # write_changed_relationships true end def _create_node(*args) session = self.class.neo4j_session props = self.class.default_property_values(self) props.merge!(args[0]) if args[0].is_a?(Hash) set_classname(props) labels = self.class.mapped_label_names session.create_node(props, labels) end module ClassMethods # Creates a saves a new node # @param [Hash] props the properties the new node should have def create(props = {}) association_props = extract_association_attributes!(props) new(props).tap do |obj| obj.save association_props.each do |prop, value| obj.send("#{prop}=", value) end end end # Same as #create, but raises an error if there is a problem during save. def create!(*args) props = args[0] || {} association_props = extract_association_attributes!(props) new(*args).tap do |o| yield o if block_given? o.save! association_props.each do |prop, value| o.send("#{prop}=", value) end end end def load_entity(id) Neo4j::Node.load(id) end end private end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
neo4j-3.0.0.rc.3 | lib/neo4j/active_node/persistence.rb |