Sha256: 1cd0452f93fb8640656b2e5dc224d214f32eb9350f437215ca0dac410ae9d94d

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# Order Item 是订单项。

class Unidom::Order::OrderItem < ActiveRecord::Base

  self.table_name = 'unidom_order_items'

  validates :ordinal,         presence: true, numericality: { only_integer: true, greater_than: 0, less_than: 1000000000 }
  validates :unit_price,      presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
  validates :quantity,        presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
  validates :purchase_amount, presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
  validates :subtotal_amount, presence: true, numericality: { less_than: 1000000000, greater_than: 0 }

  belongs_to :order,   class_name:  'Unidom::Order::Order'
  belongs_to :ordered, polymorphic: true
  belongs_to :placer,  polymorphic: true

  has_many :adjustments, class_name: 'Unidom::Order::OrderAdjustment', as: :adjusted

  scope :order_is,   ->(order)   { where order_id: (order.respond_to?(:id) ? order.id : order) }
  scope :ordered_is, ->(ordered) { where ordered: ordered }
  scope :placed_by,  ->(placer)  { where placer:  placer  }

  include Unidom::Common::Concerns::ModelExtension

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-order-0.2 app/models/unidom/order/order_item.rb