pet state order fix, and maybe some contribution fixes
This commit is contained in:
parent
3aeeac3bfc
commit
8ff6c5ad9c
4 changed files with 6 additions and 1 deletions
|
@ -63,6 +63,7 @@ class Pet < ActiveRecord::Base
|
|||
|
||||
before_validation do
|
||||
pet_type.save!
|
||||
@pet_state.save!
|
||||
items.each do |item|
|
||||
item.handle_assets!
|
||||
item.save!
|
||||
|
|
|
@ -12,6 +12,9 @@ class PetState < ActiveRecord::Base
|
|||
|
||||
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)
|
||||
self.contributions.each do |contribution|
|
||||
contribution.contributed = main_pet_state
|
||||
|
|
|
@ -34,7 +34,7 @@ class PetType < ActiveRecord::Base
|
|||
|
||||
def as_json(options={})
|
||||
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
|
||||
{:image_hash => image_hash}
|
||||
end
|
||||
|
|
|
@ -23,6 +23,7 @@ class User < ActiveRecord::Base
|
|||
self.points += new_points
|
||||
Pet.transaction do
|
||||
pet.save!
|
||||
new_contributions.each(&:save!)
|
||||
save!
|
||||
end
|
||||
new_points
|
||||
|
|
Loading…
Reference in a new issue