From f0f9033b8f7558fc985dfe61ced6c20fc6806d07 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 22 Jul 2023 13:32:29 -0700 Subject: [PATCH] Fix select bug in Item.all_by_ids_or_children Idk why, but when the `select` was the first thing in the query, it was getting ignored. I wonder if there's something about the `object_assets` scope that I'm not understanding that's overwriting it? Or the `joins`? But whatever, this works, I'm not worried about it for now! --- app/models/item.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/item.rb b/app/models/item.rb index 3c1b9302..1828fc72 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -436,11 +436,11 @@ class Item < ActiveRecord::Base swf_assets_by_id[id] = swf_asset swf_asset_ids << id end - SwfAsset.select([ + SwfAsset.object_assets.joins(:parent_swf_asset_relationships). + where(SwfAsset.arel_table[:id].in(swf_asset_ids)).select([ SwfAsset.arel_table[:id], ParentSwfAssetRelationship.arel_table[:parent_id] - ]).object_assets.joins(:parent_swf_asset_relationships). - where(SwfAsset.arel_table[:id].in(swf_asset_ids)).each do |row| + ]).each do |row| item_id = row.parent_id.to_i swf_assets_by_parent_id[item_id] ||= [] swf_assets_by_parent_id[item_id] << swf_assets_by_id[row.id.to_i]