diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 0938a4ac..0b315f8e 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -71,9 +71,12 @@ class ItemsController < ApplicationController @basic_colored_pet_types_by_species_id = PetType.special_color_or_basic(@item.special_color). includes_child_translations.group_by(&:species) + trading_closet_hangers = @item.closet_hangers.trading.newest. + includes(:user) + @trading_closet_hangers_by_owned = { - true => @item.closet_hangers.owned_trading.newest.includes(:user), - false => @item.closet_hangers.wanted_trading.newest.includes(:user) + true => trading_closet_hangers.filter { |c| c.owned? }, + false => trading_closet_hangers.filter { |c| c.wanted? }, } if user_signed_in? diff --git a/app/models/closet_hanger.rb b/app/models/closet_hanger.rb index 78a820f4..6b15ddc6 100644 --- a/app/models/closet_hanger.rb +++ b/app/models/closet_hanger.rb @@ -47,20 +47,6 @@ class ClosetHanger < ApplicationRecord scope :owned_before_wanted, -> { order(arel_table[:owned].desc) } scope :unlisted, -> { where(:list_id => nil) } - {:owned => true, :wanted => false}.each do |name, owned| - scope "#{name}_trading", -> { - joins(:user).includes(:list). - where(:owned => owned). - where(( - arel_table[:list_id].eq(nil).and( - User.arel_table["#{name}_closet_hangers_visibility"].gteq(ClosetVisibility[:trading].id) - ) - ).or( - ClosetList.arel_table[:visibility].gteq(ClosetVisibility[:trading].id) - )) - } - end - before_validation :merge_quantities, :set_owned_by_list after_save :log_trade_activity, if: :trading? @@ -74,6 +60,10 @@ class ClosetHanger < ApplicationRecord possibly_null_closet_list.trading? end + def wanted? + !owned? + end + def possibly_null_list_id=(list_id_or_owned) if list_id_or_owned.to_s == 'true' || list_id_or_owned.to_s == 'false' self.list_id = nil