Skip to content

Commit 22276e5

Browse files
michebblekbrock
authored andcommitted
Delegate Base.exists? to Relation
We can use the Relation implementation of exists? and then delegate the method on Base. This will give us one implementation that can be used on but the record class or a scoped relation.
1 parent 7b98b60 commit 22276e5

1 file changed

Lines changed: 1 addition & 15 deletions

File tree

lib/active_hash/base.rb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,6 @@ def data=(array_of_hashes)
103103
end
104104
end
105105

106-
def exists?(args = :none)
107-
if args.respond_to?(:id)
108-
record_index[args.id.to_s].present?
109-
elsif !args
110-
false
111-
elsif args == :none
112-
all.present?
113-
elsif args.is_a?(Hash)
114-
all.where(args).present?
115-
else
116-
all.where(id: args.to_s).present?
117-
end
118-
end
119-
120106
def insert(record)
121107
@records ||= []
122108
record[:id] ||= next_id
@@ -190,7 +176,7 @@ def all(options = {})
190176
relation
191177
end
192178

193-
delegate :where, :find_each, :find, :find_by, :find_by!, :find_by_id, :count, :pluck, :ids, :pick, :first, :last, :order, to: :all
179+
delegate :exists?, :where, :find_each, :find, :find_by, :find_by!, :find_by_id, :count, :pluck, :ids, :pick, :first, :last, :order, to: :all
194180

195181
def transaction
196182
yield

0 commit comments

Comments
 (0)