DEV: Concerns can use class_methods (#24875)

This commit is contained in:
Daniel Waterworth 2023-12-13 14:12:03 -06:00 committed by GitHub
parent 0513865c3c
commit f7aefffea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 3 deletions

View File

@ -84,7 +84,7 @@ module HasCustomFields
DEFAULT_FIELD_DESCRIPTOR = FieldDescriptor.new(:string, 10_000_000) DEFAULT_FIELD_DESCRIPTOR = FieldDescriptor.new(:string, 10_000_000)
CUSTOM_FIELDS_MAX_ITEMS = 100 CUSTOM_FIELDS_MAX_ITEMS = 100
module ClassMethods class_methods do
# To avoid n+1 queries, use this function to retrieve lots of custom fields in one go # To avoid n+1 queries, use this function to retrieve lots of custom fields in one go
# and create a "sideloaded" version for easy querying by id. # and create a "sideloaded" version for easy querying by id.
def custom_fields_for_ids(ids, allowed_fields) def custom_fields_for_ids(ids, allowed_fields)
@ -167,8 +167,6 @@ module HasCustomFields
end end
included do included do
extend ClassMethods
has_many :_custom_fields, dependent: :destroy, class_name: "#{name}CustomField" has_many :_custom_fields, dependent: :destroy, class_name: "#{name}CustomField"
validate :custom_fields_max_items, unless: :custom_fields_clean? validate :custom_fields_max_items, unless: :custom_fields_clean?