这里做粗略的检查，因为validation和persistence是两个阶段，加锁也不能保证原子性，validation阶段粗略的检查好处是，可以抛出合适的error给前台，提升一点用户体验。

On 2013-8-12, at 下午5:31, aptx4869 <notifications@github.com> wrote:

> In app/models/event_order.rb:
> 
> > @@ -4,6 +4,15 @@ class EventOrder < ActiveRecord::Base
> >    has_many :items, class_name: 'EventOrderItem', foreign_key: "order_id"
> >    priceable :price
> >  
> > +  validates :event_id, :user_id, :presence => true
> > +  validate do
> > +    # order_quantity = self.items.inject(0) { |sum, i| sum + i.quantity }
> > +    order_quantity = self.quantity || 0
> > +    if event.tickets_quantity == 0 || order_quantity > event.tickets_quantity
> 这玩意不是应该要加锁或者用atomic operation什么的么……
> 
> —
> Reply to this email directly or view it on GitHub.
>