mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 13:33:44 +08:00
55a1394342
Doing .pluck(:column).first is a very common pattern in Discourse and in most cases, a limit cause isn't being added. Instead of adding a limit clause to all these callsites, this commit adds two new methods to ActiveRecord::Relation: pluck_first, equivalent to limit(1).pluck(*columns).first and pluck_first! which, like other finder methods, raises an exception when no record is found
17 lines
324 B
Ruby
17 lines
324 B
Ruby
# frozen_string_literal: true
|
|
|
|
class BackupMetadata < ActiveRecord::Base
|
|
def self.value_for(name)
|
|
where(name: name).pluck_first(:value).presence
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: backup_metadata
|
|
#
|
|
# id :bigint not null, primary key
|
|
# name :string not null
|
|
# value :string
|
|
#
|