1
0
Fork 0
forked from OpenNeo/impress

fix ClosetHanger.set_quantity to not call destroy on a new hanger; it confuses flex

This commit is contained in:
Emi Matchu 2013-01-25 10:44:15 -06:00
parent 7f18fe12c1
commit d0dffd6cff

View file

@ -69,23 +69,28 @@ class ClosetHanger < ActiveRecord::Base
end end
hanger = self.where(conditions).first hanger = self.where(conditions).first
unless hanger
hanger = self.new
hanger.user_id = conditions[:user_id]
hanger.item_id = conditions[:item_id]
# One of the following will be nil, and that's okay. If owned is nil,
# we'll cover for it before validation, as always.
hanger.owned = conditions[:owned]
hanger.list_id = conditions[:list_id]
end
unless quantity == 0 if quantity > 0
Rails.logger.debug("Logging to #{hanger.id} quantity #{quantity}") # If quantity is non-zero, create/update the corresponding hanger.
unless hanger
hanger = self.new
hanger.user_id = conditions[:user_id]
hanger.item_id = conditions[:item_id]
# One of the following will be nil, and that's okay. If owned is nil,
# we'll cover for it before validation, as always.
hanger.owned = conditions[:owned]
hanger.list_id = conditions[:list_id]
end
hanger.quantity = quantity hanger.quantity = quantity
hanger.save! hanger.save!
else elsif hanger
hanger.destroy if hanger # If quantity is zero and there's a hanger, destroy it.
hanger.destroy
end end
# If quantity is zero and there's no hanger, good. Do nothing.
end end
protected protected