-
Notifications
You must be signed in to change notification settings - Fork 275
Search and Scope
Andreas Ronge edited this page Aug 28, 2014
·
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)
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