Sha256: 818e043872117cd00a848a533e8b45ab56a64540fe0cc07fdfefb2a620466965

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

##
# Shopping Item 是购物项。

module Unidom
  module Shopping

    class ShoppingItem < 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: Unidom::Common::MAXIMUM_AMOUNT }
      validates :quantity,   presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Unidom::Common::MAXIMUM_AMOUNT }

      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: 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'

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-shopping-2.0.1 app/models/unidom/shopping/shopping_item.rb