Skip to content

Project Introduction

subvertallchris edited this page Dec 5, 2014 · 1 revision

Neo4j.rb is an ActiveRecord replacement for Rails supporting Neo4j 2.1+.

Compared to Neo4j.rb 2.x, 3.0 is a complete rebuild that boasts support for Ruby MRI using the Neo4j REST endpoint, a smaller and simpler codebase, improved Cypher Query DSL, and a more ActiveRecord-like feel. Neo4j embedded is still supported for those seeking its performance benefits under JRuby and the Neo4j embedded traversal API. See the Setup section for configuration.

v4 builds upon v3, adjusting defaults and removing the need for _classname properties when used with Neo4j 2.1.5+.

Getting Started Resources

Introduction screencast: https://www.youtube.com/watch?v=bDjbqRL9HcM Introduction blog: http://www.jayway.com/2014/09/06/neo4j-rb-3-0-rc/

What does it look like?

class Student
  include Neo4j::ActiveNode
  property :name
  property :age
  has_many :out, :lessons, type: 'enrolled_in'
end

class Lesson
  include Neo4j::ActiveNode
  property :subject
  has_many :in, :students, origin: :lessons
end

sandra = Student.find_by(name: 'Sandra', age: 15)

# sandra's lessons
sandra.lessons.each{|l| puts l.full_name }

# sandra's classmates
sandra.lessons.students.each_with_rel{ |student, rel| puts "#{student.name} is enrolled in #{rel.to_node.subject}" }

# sandra's classmates, age < 16
sandra.lessons.students(:s).where('s.age < {age}').params(age: 16).each_with_rel{|student, rel| puts "#{student.name} is enrolled in #{rel.to_node.subject" }

Neo4j-core

Neo4j.rb uses neo4j-core for database communication, its Cypher DSL, and many of its basic methods and classes. Please see that gem's README for more information, as familiarity with it will be helpful as you learn this gem.

Clone this wiki locally