Merge branch 'bugmash'

This commit is contained in:
Emi Matchu 2010-11-25 21:33:37 -05:00
commit 8447667f62
4 changed files with 11 additions and 6 deletions

View file

@ -10,11 +10,10 @@ class SwfAssetsController < ApplicationController
end
elsif params[:body_id] && params[:item_ids]
swf_assets = SwfAsset.arel_table
rels = ParentSwfAssetRelationship.arel_table
@swf_assets = SwfAsset.select('swf_assets.*, parents_swf_assets.parent_id').
@swf_assets = SwfAsset.object_assets.
select('swf_assets.*, parents_swf_assets.parent_id').
fitting_body_id(params[:body_id]).
joins(:object_asset_relationships).
where(rels[:parent_id].in(params[:item_ids]))
for_item_ids(params[:item_ids])
json = @swf_assets.map { |a| a.as_json(:parent_id => a.parent_id.to_i, :for => 'wardrobe') }
elsif params[:pet_state_id]
@swf_assets = PetState.find(params[:pet_state_id]).swf_assets.all

View file

@ -4,7 +4,8 @@ class Item < ActiveRecord::Base
has_one :contribution, :as => :contributed
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id',
: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

View file

@ -5,7 +5,8 @@ class PetState < ActiveRecord::Base
has_many :outfits
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id',
: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

View file

@ -22,6 +22,10 @@ class SwfAsset < ActiveRecord::Base
scope :biology_assets, where(arel_table[:type].eq(PetState::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
'/' + File.join(PUBLIC_ASSET_DIR, local_path_within_outfit_swfs)