Skip to content

Commit

Permalink
Loading collections for a PrefLabel now removes non-unique collection…
Browse files Browse the repository at this point in the history
…s from the result.
  • Loading branch information
pschijven committed Oct 17, 2023
1 parent 22b3cdc commit bb00450
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 12 additions & 5 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def index
end
format.json do # For the widget and treeview
response = if params[:root].present?
collections = Iqvoc::Collection.base_class.with_pref_labels.published.by_parent_id(params[:root])
collections = Iqvoc::Collection.base_class
.with_pref_labels
.published
.by_parent_id(params[:root])
.sort_by { |c| c.pref_label.to_s }

collections.map do |collection|
res = {
id: collection.id,
Expand All @@ -46,10 +51,12 @@ def index
res
end
else
collections = Iqvoc::Collection.base_class.with_pref_labels.published.merge(Label::Base.by_query_value("#{params[:query]}%"))
collections.map do |c|
collection_widget_data(c)
end
collections = Iqvoc::Collection.base_class
.with_pref_labels
.published
.merge(Label::Base.by_query_value("#{params[:query]}%"))
.sort_by { |c| c.pref_label.to_s }
.map { |c| collection_widget_data(c) }
end
render json: response
end
Expand Down
5 changes: 4 additions & 1 deletion app/models/collection/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class Collection::Base < Concept::Base
validate :circular_subcollections

def self.with_pref_labels
super.references(:collection_members)
preload(:pref_labels)
.joins(:pref_labels)
.references(:collection_members)
.distinct
end

def self.by_origin(origin)
Expand Down

0 comments on commit bb00450

Please sign in to comment.