app/controllers/collections_controller.rb in iqvoc-4.13.2 vs app/controllers/collections_controller.rb in iqvoc-4.14.4

- old
+ new

@@ -27,15 +27,20 @@ @top_collections.tops end @top_collections.to_a.sort! { |a, b| a.pref_label.to_s <=> b.pref_label.to_s } - ActiveRecord::Associations::Preloader.new.preload(@top_collections, { members: :target }) + Iqvoc::Collection.base_class.preload(@top_collections, { members: :target }) 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, url: collection_path(id: collection, format: :html), name: CGI.escapeHTML(collection.pref_label.to_s), @@ -44,14 +49,16 @@ res[:additionalText] = " (#{collection.additional_info})" if collection.additional_info 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 end end @@ -70,11 +77,11 @@ @collection = scope.last! authorize! :read, @collection # When in single query mode, AR handles ALL includes to be loaded by that # one query. We don't want that! So let's do it manually :-) - ActiveRecord::Associations::Preloader.new.preload(@collection, + Iqvoc::Collection.base_class.preload(@collection, [:pref_labels, { members: { target: [:pref_labels] + Iqvoc::Collection.base_class.default_includes } }]) respond_to do |format| format.html { published ? render('show_published') : render('show_unpublished') } @@ -109,10 +116,10 @@ @collection = Iqvoc::Collection.base_class.by_origin(params[:id]).last! authorize! :update, @collection # When in single query mode, AR handles ALL includes to be loaded by that # one query. We don't want that! So let's do it manually :-) - ActiveRecord::Associations::Preloader.new.preload(@collection, [ + Iqvoc::Collection.base_class.preload(@collection, [ :pref_labels, { members: { target: [:pref_labels] + Iqvoc::Concept.base_class.default_includes } }]) build_note_relations end