1
0
Fork 0
forked from OpenNeo/impress
impress/app/models/closet_hanger.rb

21 lines
544 B
Ruby
Raw Normal View History

2011-07-12 16:37:16 -07:00
class ClosetHanger < ActiveRecord::Base
belongs_to :item
belongs_to :user
attr_accessible :owned, :quantity
2011-07-14 09:50:24 -07:00
validates :item_id, :uniqueness => {:scope => [:user_id, :owned]}
2011-07-14 09:50:24 -07:00
validates :quantity, :numericality => {:greater_than => 0}
validates_presence_of :item, :user
2011-07-12 16:37:16 -07:00
scope :alphabetical_by_item_name, joins(:item).order(Item.arel_table[:name])
scope :owned_before_wanted, order(arel_table[:owned].desc)
def verb(subject=:someone)
base = (owned?) ? 'own' : 'want'
base + 's' if subject != :you
base
end
2011-07-12 16:37:16 -07:00
end