Sha256: ed8385057d47c9a131a542c607a7021e7bc96bf44c47be2b648b85ab9a9d3185

Contents?: true

Size: 1004 Bytes

Versions: 2

Compression:

Stored size: 1004 Bytes

Contents

##
# Shopping Item 是购物项。

class Unidom::Shopping::ShoppingItem < Unidom::Shopping::ApplicationRecord

  self.table_name = 'unidom_shopping_items'

  include Unidom::Common::Concerns::ModelExtension

  validates :unit_price, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
  validates :quantity,   presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }

  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: to_id(shopping_cart) }
  scope :shopped_by,       ->(shopper)       { where shopper:          shopper              }
  scope :shopped_is,       ->(shopped)       { where shopped:          shopped              }

end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingItem'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unidom-shopping-1.7.5 app/models/unidom/shopping/shopping_item.rb
unidom-shopping-1.7.4 app/models/unidom/shopping/shopping_item.rb