From 7313040466a709aad1396b6e1b8cad4b18b6514f Mon Sep 17 00:00:00 2001 From: Giallombardo Nathan Date: Mon, 21 Aug 2023 13:42:11 +0000 Subject: [PATCH] implement remove_multi (cherry picked from commit 5a6f487fed315fb20bf0e3c7de4db809e2c06d48) --- lib/couchbase-orm/proxies/collection_proxy.rb | 16 ++++++++++++++++ lib/couchbase-orm/relation.rb | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/couchbase-orm/proxies/collection_proxy.rb b/lib/couchbase-orm/proxies/collection_proxy.rb index 9ddf54c6..0d1c94bc 100644 --- a/lib/couchbase-orm/proxies/collection_proxy.rb +++ b/lib/couchbase-orm/proxies/collection_proxy.rb @@ -35,6 +35,22 @@ def remove(id, **options) nil end + def remove_multi!(ids, **options) + result = @proxyfied.remove_multi(ids, Couchbase::Options::RemoveMulti.new(**options)) + first_result_with_error = result.find(&:error) + if first_result_with_error + raise CouchbaseOrm::Error::DocumentNotFound + end + result + end + + def remove_multi(ids, **options) + result = @proxyfied.remove_multi(ids, Couchbase::Options::RemoveMulti.new(**options)) + result.reject(&:error) + end + + + def initialize(proxyfied) raise "Must proxy a non nil object" if proxyfied.nil? @proxyfied = proxyfied diff --git a/lib/couchbase-orm/relation.rb b/lib/couchbase-orm/relation.rb index 8a92ece7..19d72890 100644 --- a/lib/couchbase-orm/relation.rb +++ b/lib/couchbase-orm/relation.rb @@ -103,7 +103,7 @@ def [](*args) def delete_all CouchbaseOrm::logger.debug{ "Delete all: #{self}" } ids = query.to_a - CouchbaseOrm::Connection.bucket.default_collection.remove_multi(ids) unless ids.empty? + @model.collection.remove_multi(ids) unless ids.empty? end def where(string_cond=nil, **conds)