1
0
Fork 0
forked from OpenNeo/impress

bring needed items queries up-to-date with new species support ID syntax

This commit is contained in:
Emi Matchu 2013-02-20 00:52:37 -06:00
parent 4921ed964a
commit 0e2e83ef56

View file

@ -89,26 +89,28 @@ class PetType < ActiveRecord::Base
end end
def needed_items def needed_items
items = Item.arel_table # If I need this item on a pet type, that means that we've already seen it
species_matchers = [ # and it's body-specific. So, there's a body-specific asset for the item,
"#{species_id},%", # but no asset that fits this pet type.
"%,#{species_id},%", i = Item.arel_table
"%,#{species_id}" psa = ParentSwfAssetRelationship.arel_table
] sa = SwfAsset.arel_table
species_condition = nil
species_matchers.each do |matcher| # Close, but no cigar: if we just check for the presence of *one* other
condition = items[:species_support_ids].matches(matcher) # body-specific asset, it'll also include single-species items for other
if species_condition # species. We should check for more than one... but I'm not sure how to
species_condition = species_condition.or(condition) # do that in Arel...
else Item.where('(' + ParentSwfAssetRelationship.select('count(*)').joins(:swf_asset).
species_condition = condition where(
end psa[:parent_id].eq(i[:id]).and(
end psa[:parent_type].eq('Item').and(
unneeded_item_ids = Item.select(items[:id]). sa[:body_id].not_eq(self.body_id)))
joins(:parent_swf_asset_relationships => :swf_asset). ).to_sql + ') > 1').
where(SwfAsset.arel_table[:body_id].in([0, self.body_id])).map(&:id) where(ParentSwfAssetRelationship.joins(:swf_asset).where(
Item.where(items[:id].not_in(unneeded_item_ids)). psa[:parent_id].eq(i[:id]).and(
where(species_condition) psa[:parent_type].eq('Item').and(
sa[:body_id].in([self.body_id, 0])))
).exists.not)
end end
def add_pet_state_from_biology!(biology) def add_pet_state_from_biology!(biology)