diff options
Diffstat (limited to 'app/models/concerns/taggable_queries.rb')
-rw-r--r-- | app/models/concerns/taggable_queries.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/app/models/concerns/taggable_queries.rb b/app/models/concerns/taggable_queries.rb index cba2e93a86d..06799f0a9f4 100644 --- a/app/models/concerns/taggable_queries.rb +++ b/app/models/concerns/taggable_queries.rb @@ -3,6 +3,10 @@ module TaggableQueries extend ActiveSupport::Concern + MAX_TAGS_IDS = 50 + + TooManyTagsError = Class.new(StandardError) + class_methods do # context is a name `acts_as_taggable context` def arel_tag_names_array(context = :tags) @@ -34,4 +38,10 @@ module TaggableQueries where("EXISTS (?)", matcher) end end + + def tags_ids + tags.limit(MAX_TAGS_IDS).order('id ASC').pluck(:id).tap do |ids| + raise TooManyTagsError if ids.size >= MAX_TAGS_IDS + end + end end |