ensure that we're only returning item assets for items and biology assets for pet states
This commit is contained in:
parent
55ab3d56d5
commit
99fb6b984f
4 changed files with 11 additions and 6 deletions
|
@ -10,11 +10,10 @@ class SwfAssetsController < ApplicationController
|
||||||
end
|
end
|
||||||
elsif params[:body_id] && params[:item_ids]
|
elsif params[:body_id] && params[:item_ids]
|
||||||
swf_assets = SwfAsset.arel_table
|
swf_assets = SwfAsset.arel_table
|
||||||
rels = ParentSwfAssetRelationship.arel_table
|
@swf_assets = SwfAsset.object_assets.
|
||||||
@swf_assets = SwfAsset.select('swf_assets.*, parents_swf_assets.parent_id').
|
select('swf_assets.*, parents_swf_assets.parent_id').
|
||||||
fitting_body_id(params[:body_id]).
|
fitting_body_id(params[:body_id]).
|
||||||
joins(:object_asset_relationships).
|
for_item_ids(params[:item_ids])
|
||||||
where(rels[:parent_id].in(params[:item_ids]))
|
|
||||||
json = @swf_assets.map { |a| a.as_json(:parent_id => a.parent_id.to_i, :for => 'wardrobe') }
|
json = @swf_assets.map { |a| a.as_json(:parent_id => a.parent_id.to_i, :for => 'wardrobe') }
|
||||||
elsif params[:pet_state_id]
|
elsif params[:pet_state_id]
|
||||||
@swf_assets = PetState.find(params[:pet_state_id]).swf_assets.all
|
@swf_assets = PetState.find(params[:pet_state_id]).swf_assets.all
|
||||||
|
|
|
@ -4,7 +4,8 @@ class Item < ActiveRecord::Base
|
||||||
has_one :contribution, :as => :contributed
|
has_one :contribution, :as => :contributed
|
||||||
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id',
|
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id',
|
||||||
:conditions => {:swf_asset_type => SwfAssetType}
|
:conditions => {:swf_asset_type => SwfAssetType}
|
||||||
has_many :swf_assets, :through => :parent_swf_asset_relationships, :source => :object_asset
|
has_many :swf_assets, :through => :parent_swf_asset_relationships, :source => :object_asset,
|
||||||
|
:conditions => {:type => SwfAssetType}
|
||||||
|
|
||||||
attr_writer :current_body_id
|
attr_writer :current_body_id
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ class PetState < ActiveRecord::Base
|
||||||
has_many :outfits
|
has_many :outfits
|
||||||
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id',
|
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id',
|
||||||
:conditions => {:swf_asset_type => SwfAssetType}
|
:conditions => {:swf_asset_type => SwfAssetType}
|
||||||
has_many :swf_assets, :through => :parent_swf_asset_relationships, :source => :biology_asset
|
has_many :swf_assets, :through => :parent_swf_asset_relationships, :source => :biology_asset,
|
||||||
|
:conditions => {:type => SwfAssetType}
|
||||||
|
|
||||||
belongs_to :pet_type
|
belongs_to :pet_type
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,10 @@ class SwfAsset < ActiveRecord::Base
|
||||||
|
|
||||||
scope :biology_assets, where(arel_table[:type].eq(PetState::SwfAssetType))
|
scope :biology_assets, where(arel_table[:type].eq(PetState::SwfAssetType))
|
||||||
scope :object_assets, where(arel_table[:type].eq(Item::SwfAssetType))
|
scope :object_assets, where(arel_table[:type].eq(Item::SwfAssetType))
|
||||||
|
scope :for_item_ids, lambda { |item_ids|
|
||||||
|
joins(:object_asset_relationships).
|
||||||
|
where(ParentSwfAssetRelationship.arel_table[:parent_id].in(item_ids))
|
||||||
|
}
|
||||||
|
|
||||||
def local_url
|
def local_url
|
||||||
'/' + File.join(PUBLIC_ASSET_DIR, local_path_within_outfit_swfs)
|
'/' + File.join(PUBLIC_ASSET_DIR, local_path_within_outfit_swfs)
|
||||||
|
|
Loading…
Reference in a new issue