Module: ActiveGraph::Node::Labels::Index::ClassMethods

Extended by:
Forwardable
Defined in:
lib/active_graph/node/labels/index.rb

Instance Method Summary collapse

Instance Method Details

#constraint(property, _constraints = {type: :unique}) ⇒ Object

Creates a neo4j constraint on this class for given property

Examples:

Person.constraint :name, type: :unique


32
33
34
# File 'lib/active_graph/node/labels/index.rb', line 32

def constraint(property, _constraints = {type: :unique})
  ActiveGraph::ModelSchema.add_defined_constraint(self, property)
end

#index(property) ⇒ Object

Creates a Neo4j index on given property

This can also be done on the property directly, see ActiveGraph::Node::Property::ClassMethods#property.

Examples:

class Person
   include ActiveGraph::Node
   property :name
   index :name
 end

Parameters:

  • property (Symbol)

    the property we want a Neo4j index on



22
23
24
25
26
# File 'lib/active_graph/node/labels/index.rb', line 22

def index(property)
  return if ActiveGraph::ModelSchema.defined_constraint?(self, property)

  ActiveGraph::ModelSchema.add_defined_index(self, property)
end