Fix body ID bug saving SwfAsset outside modeling
Oops, if you saved `SwfAsset` outside of modeling code, the `item` field would be empty, and so `item.body_specific?` wouldn't happen. This would trigger when you even just report a broken image! Now, we always run the SQL query to check for that flag.
This commit is contained in:
parent
6697b15413
commit
238a458131
1 changed files with 16 additions and 2 deletions
|
@ -209,8 +209,22 @@ class SwfAsset < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def body_specific?
|
||||
Rails.logger.debug("my zone id is: #{zone_id}")
|
||||
self.zone.type_id < 3 || (item && item.body_specific?)
|
||||
self.zone.type_id < 3 || item_is_body_specific?
|
||||
end
|
||||
|
||||
def item_is_body_specific?
|
||||
# Get items that we're already bound to in the database, and
|
||||
# also the one passed to us from the current modeling operation,
|
||||
# if any.
|
||||
#
|
||||
# NOTE: I know this has perf impact... it would be better for
|
||||
# modeling to preload this probably? But oh well!
|
||||
items = parent_swf_asset_relationships.includes(:parent).where(parent_type: "Item").map { |r| r.parent }
|
||||
items << item if item
|
||||
|
||||
# Return whether any of them is known to be body-specific.
|
||||
# This ensures that we always respect the explicitly_body_specific flag!
|
||||
return items.any? { |i| i.body_specific? }
|
||||
end
|
||||
|
||||
def origin_pet_type=(pet_type)
|
||||
|
|
Loading…
Reference in a new issue