ClassMethods

Constants

Methods

#create

Creates and saves a new node

def create(props = {})
  association_props = extract_association_attributes!(props) || {}
  new(props).tap do |obj|
    yield obj if block_given?
    obj.save
    association_props.each do |prop, value|
      obj.send("#{prop}=", value)
    end
  end
end
#create!

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

#find_or_create

def find_or_create(find_attributes, set_attributes = {})
  on_create_attributes = set_attributes.reverse_merge(on_create_props(find_attributes))
  neo4j_session.query.merge(n: {self.mapped_label_names => find_attributes})
    .on_create_set(n: on_create_attributes)
    .pluck(:n).first
end
#find_or_create_by

Finds the first node with the given attributes, or calls create if none found

def find_or_create_by(attributes, &block)
  find_by(attributes) || create(attributes, &block)
end
#find_or_create_by!

Same as #find_or_create_by, but calls #create! so it raises an error if there is a problem during save.

def find_or_create_by!(attributes, &block)
  find_by(attributes) || create!(attributes, &block)
end

#load_entity

def load_entity(id)
  Neo4j::Node.load(id)
end

#merge

def merge(attributes)
  neo4j_session.query.merge(n: {self.mapped_label_names => attributes})
    .on_create_set(n: on_create_props(attributes))
    .on_match_set(n: on_match_props)
    .pluck(:n).first
end