Sha256: 64d37b049165f1d2cfcdec9c889f7bcaabff268cf6dfc29c456f580099b7100f

Contents?: true

Size: 845 Bytes

Versions: 9

Compression:

Stored size: 845 Bytes

Contents

# Shopping Item 是购物项。

class Unidom::Shopping::ShoppingItem < ActiveRecord::Base

  self.table_name = 'unidom_shopping_items'

  include Unidom::Common::Concerns::ModelExtension

  validates :unit_price, presence: true, numericality: { greater_than: 0, less_than: 1000000000 }
  validates :quantity,   presence: true, numericality: { greater_than: 0, less_than: 1000000000 }

  belongs_to :shopping_cart, class_name: 'Unidom::Shopping::ShoppingCart'
  belongs_to :shopper,       polymorphic: true
  belongs_to :shopped,       polymorphic: true

  scope :shopping_cart_is, ->(shopping_cart) { where shopping_cart_id: (shopping_cart.respond_to?(:id) ? shopping_cart.id : shopping_cart) }
  scope :shopped_by,       ->(shopper)       { where shopper: shopper }
  scope :shopped_is,       ->(shopped)       { where shopped: shopped }

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
unidom-shopping-1.6 app/models/unidom/shopping/shopping_item.rb
unidom-shopping-1.5 app/models/unidom/shopping/shopping_item.rb
unidom-shopping-1.4 app/models/unidom/shopping/shopping_item.rb
unidom-shopping-1.3 app/models/unidom/shopping/shopping_item.rb
unidom-shopping-1.2 app/models/unidom/shopping/shopping_item.rb
unidom-shopping-1.1 app/models/unidom/shopping/shopping_item.rb
unidom-shopping-1.0.1 app/models/unidom/shopping/shopping_item.rb
unidom-shopping-1.0 app/models/unidom/shopping/shopping_item.rb
unidom-shopping-0.3 app/models/unidom/shopping/shopping_item.rb