mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 15:05:24 +08:00
25a226279a
The #pluck_first freedom patch, first introduced by @danielwaterworth has served us well, and is used widely throughout both core and plugins. It seems to have been a common enough use case that Rails 6 introduced it's own method #pick with the exact same implementation. This allows us to retire the freedom patch and switch over to the built-in ActiveRecord method. There is no replacement for #pluck_first!, but a quick search shows we are using this in a very limited capacity, and in some cases incorrectly (by assuming a nil return rather than an exception), which can quite easily be replaced with #pick plus some extra handling.
22 lines
497 B
Ruby
22 lines
497 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ActiveRecord::Relation
|
|
def pluck_first(*attributes)
|
|
Discourse.deprecate("`#pluck_first` is deprecated, use `#pick` instead.")
|
|
pick(*attributes)
|
|
end
|
|
|
|
def pluck_first!(*attributes)
|
|
Discourse.deprecate("`#pluck_first!` is deprecated without replacement.")
|
|
items = pick(*attributes)
|
|
|
|
raise_record_not_found_exception! if items.nil?
|
|
|
|
items
|
|
end
|
|
end
|
|
|
|
module ActiveRecord::Querying
|
|
delegate(:pluck_first, :pluck_first!, to: :all)
|
|
end
|