Merge pull request #7986 from tchak/refactor-procedure-tags

refactor(procedure): expose procedure tags on model
This commit is contained in:
Paul Chavard 2022-10-31 22:14:08 +01:00 committed by GitHub
commit 2201114028
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -63,7 +63,7 @@ module Administrateurs
def new
@procedure ||= Procedure.new(for_individual: true)
@existing_tags = get_existing_tags
@existing_tags = Procedure.tags
end
SIGNIFICANT_DOSSIERS_THRESHOLD = 30
@ -403,11 +403,5 @@ module Administrateurs
def cloned_from_library?
params[:from_new_from_existing].present?
end
def get_existing_tags
unnest = Arel::Nodes::NamedFunction.new('UNNEST', [Procedure.arel_table[:tags]])
query = Procedure.select(unnest.as('tags')).distinct.order('tags')
Procedure.connection.query(query.to_sql).flatten
end
end
end

View file

@ -833,6 +833,12 @@ class Procedure < ApplicationRecord
published_at || created_at
end
def self.tags
unnest = Arel::Nodes::NamedFunction.new('UNNEST', [self.arel_table[:tags]])
query = self.select(unnest.as('tags')).distinct.order('tags')
self.connection.query(query.to_sql).flatten
end
private
def move_new_children_to_new_parent_coordinate(new_draft)