1
0
Fork 0
forked from OpenNeo/impress

pet state order fix, and maybe some contribution fixes

This commit is contained in:
Emi Matchu 2011-02-22 17:54:20 -05:00
parent 3aeeac3bfc
commit 8ff6c5ad9c
4 changed files with 6 additions and 1 deletions

View file

@ -63,6 +63,7 @@ class Pet < ActiveRecord::Base
before_validation do before_validation do
pet_type.save! pet_type.save!
@pet_state.save!
items.each do |item| items.each do |item|
item.handle_assets! item.handle_assets!
item.save! item.save!

View file

@ -12,6 +12,9 @@ class PetState < ActiveRecord::Base
alias_method :swf_asset_ids_from_association, :swf_asset_ids alias_method :swf_asset_ids_from_association, :swf_asset_ids
scope :emotion_order, joins(:parent_swf_asset_relationships).
group("pet_states.id").order("COUNT(parents_swf_assets.swf_asset_id) DESC, SUM(parents_swf_assets.swf_asset_id) ASC")
def reassign_children_to!(main_pet_state) def reassign_children_to!(main_pet_state)
self.contributions.each do |contribution| self.contributions.each do |contribution|
contribution.contributed = main_pet_state contribution.contributed = main_pet_state

View file

@ -34,7 +34,7 @@ class PetType < ActiveRecord::Base
def as_json(options={}) def as_json(options={})
if options[:for] == 'wardrobe' if options[:for] == 'wardrobe'
{:id => id, :body_id => body_id, :pet_state_ids => pet_state_ids} {:id => id, :body_id => body_id, :pet_state_ids => pet_states.select([:id]).emotion_order.map(&:id)}
else else
{:image_hash => image_hash} {:image_hash => image_hash}
end end

View file

@ -23,6 +23,7 @@ class User < ActiveRecord::Base
self.points += new_points self.points += new_points
Pet.transaction do Pet.transaction do
pet.save! pet.save!
new_contributions.each(&:save!)
save! save!
end end
new_points new_points