DEV: Concerns can use class_methods (#24875)

This commit is contained in:
Daniel Waterworth 2023-12-13 14:12:03 -06:00
parent 92882d1cc3
commit 497d5b4ca0

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?