-
Notifications
You must be signed in to change notification settings - Fork 276
Search and Scope
Chris Grigg edited this page Jan 10, 2015
·
6 revisions
Scope allows you to reuse queries and make them more readable. It is also possible to combine scope queries with declared relationships, e.g. friends.top_students
, see below.
Neo4j.rb implements scope in a similar way to ActiveRecord scope
class Person
include Neo4j::ActiveNode
property :level_num
scope :level, ->(num){ where(level_num: num)}
end
Person.level(3)
class Person
include Neo4j::ActiveNode
property :name
property :score
property :level_num
has_many :out, :friends, model_class: self
scope :top_students, -> { where(score: 1000)}
end
# from one person node
a_person.friends.top_students.friends
# from all person nodes
Person.top_students.friends
class Person
include Neo4j::ActiveNode
scope :in_order, ->(identifier){ order("#{identifier}.level_num DESC")}
end
Person.as(:people).in_order(:people)
Scope was reworked in the v4 release of the gem. See this spec for a good example.
WARNING: Much of the information in this wiki is out of date. We are in the process of moving things to readthedocs
- Project Introduction
- Neo4j::ActiveNode
- Neo4j::ActiveRel
- Search and Scope
- Validation, Uniqueness, and Case Sensitivity
- Indexing VS Legacy Indexing
- Optimized Methods
- Inheritance
- Core: Nodes & Rels
- Introduction
- Persistence
- Find : Lucene
- Relationships
- Third Party Gems & extensions
- Scaffolding & Generators
- HA Cluster