lib/neo4j/active_node/labels.rb in neo4j-3.0.1 vs lib/neo4j/active_node/labels.rb in neo4j-3.0.2

- old
+ new

@@ -11,13 +11,22 @@ class RecordNotFound < StandardError; end # @return the labels # @see Neo4j-core def labels - @_persisted_obj.labels + if @_persisted_obj.labels.nil? + r = queried_labels + @_persisted_obj.labels = r + else + @_persisted_obj.labels + end 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 + # adds one or more labels # @see Neo4j-core def add_label(*label) @_persisted_obj.add_label(*label) end @@ -61,13 +70,11 @@ module ClassMethods include Neo4j::ActiveNode::QueryMethods # Find all nodes/objects of this class def all - self.query_as(:n).pluck(:n) + self.as(:n) end - - # Returns the object with the specified neo4j id. # @param [String,Fixnum] id of node to find def find(id) map_id = Proc.new {|object| object.respond_to?(:id) ? object.send(:id) : object }