lib/neo4j/active_node/labels.rb in neo4j-3.0.4 vs lib/neo4j/active_node/labels.rb in neo4j-4.0.0.rc.1
- old
+ new
@@ -11,21 +11,17 @@
class RecordNotFound < StandardError; end
# @return the labels
# @see Neo4j-core
def labels
- if @_persisted_obj.labels.nil?
- r = queried_labels
- @_persisted_obj.labels = r
- else
- @_persisted_obj.labels
- end
+ @_persisted_obj.labels
end
- def queried_labels
- self.class.query_as(:result).where("ID(result)" => self.neo_id).return("LABELS(result) as result_labels").first.result_labels.map(&:to_sym)
- end
+ # this is handled by core, leaving it now for posterity
+ # def queried_labels
+ # self.class.query_as(:result).where("ID(result)" => self.neo_id).return("LABELS(result) as result_labels").first.result_labels.map(&:to_sym)
+ # end
# adds one or more labels
# @see Neo4j-core
def add_label(*label)
@_persisted_obj.add_label(*label)
@@ -70,11 +66,11 @@
module ClassMethods
include Neo4j::ActiveNode::QueryMethods
# Find all nodes/objects of this class
def all
- self.as(:n)
+ Neo4j::ActiveNode::Query::QueryProxy.new(self, nil, {})
end
# Returns the object with the specified neo4j id.
# @param [String,Fixnum] id of node to find
def find(id)
@@ -129,12 +125,11 @@
# end
def index(property, conf = {})
Neo4j::Session.on_session_available do |_|
_index(property, conf)
end
- @_indexed_properties ||= []
- @_indexed_properties.push property unless @_indexed_properties.include? property
+ indexed_properties.push property unless indexed_properties.include? property
end
# Creates a neo4j constraint on this class for given property
#
# @example
@@ -172,10 +167,22 @@
def mapped_label
Neo4j::Label.create(mapped_label_name)
end
def indexed_properties
- @_indexed_properties
+ @_indexed_properties ||= []
+ end
+
+ def base_class
+ unless self < Neo4j::ActiveNode
+ raise "#{name} doesn't belong in a hierarchy descending from ActiveNode"
+ end
+
+ if superclass == Object
+ self
+ else
+ superclass.base_class
+ end
end
protected