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!
This commit is contained in:
Matchu 2023-07-22 13:32:29 -07:00 committed by Matchu
parent 5d12ca0b7d
commit f0f9033b8f

View file

@ -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]