lib/neo4j/active_node/labels.rb in neo4j-3.0.0.rc.3 vs lib/neo4j/active_node/labels.rb in neo4j-3.0.0.rc.4

- old
+ new

@@ -69,12 +69,17 @@ # Returns the object with the specified neo4j id. # @param [String,Fixnum] id of node to find def find(id) - raise "Unknown argument #{id.class} in find method (expected String or Fixnum)" if not [String, Fixnum].include?(id.class) - find_by_id(id) + map_id = Proc.new {|object| object.respond_to?(:id) ? object.send(:id) : object } + + if id.is_a?(Array) + find_by_ids(id.map {|o| map_id.call(o) }) + else + find_by_id(map_id.call(id)) + end end # Finds the first record matching the specified conditions. There is no implied ordering so if order matters, you should specify it yourself. # @param [Hash] args of arguments to find def find_by(*args) @@ -127,12 +132,19 @@ # # @example # Person.constraint :name, type: :unique # def constraint(property, constraints, session = Neo4j::Session.current) - Neo4j::Session.on_session_available do |_| + Neo4j::Session.on_session_available do |session| label = Neo4j::Label.create(mapped_label_name) label.create_constraint(property, constraints, session) + end + end + + def drop_constraint(property, constraint, session = Neo4j::Session.current) + Neo4j::Session.on_session_available do |session| + label = Neo4j::Label.create(mapped_label_name) + label.drop_constraint(property, constraint, session) end end def index?(index_def) mapped_label.indexes[:property_keys].include?([index_def])