Commit 48671021 by ivan Lan

Add scope :in_order & :in_cart to Snapshot

parent e002fccf
......@@ -28,7 +28,13 @@ module Shotengai
class Cart < ::ActiveRecord::Base
self.table_name = 'shotengai_orders'
default_scope { where(status: 'cart') }
#
# class Order < Shotengai::Order
# can_by 'Product'
# end
#
# Would let Product belongs to :order & order_cart
#
class << self
def can_buy *good_class_names
good_classes = good_class_names.map { |name| Object.const_get(name) }
......
......@@ -30,7 +30,8 @@ module Shotengai
class Order < ActiveRecord::Base
self.table_name = 'shotengai_orders'
belongs_to :buyer, polymorphic: true
belongs_to :buyer, polymorphic: true, optional: true
default_scope { where.not(status: 'cart') }
include AASM_DLC
......
......@@ -31,7 +31,23 @@ module Shotengai
validate :check_spec, if: :spec
validates :count, numericality: { only_integer: true, greater_than: 0 }
belongs_to :shotengai_order, optional: true
belongs_to :shotengai_order, foreign_key: :shotengai_order_id,
class_name: 'Shotengai::Order', optional: true
scope :in_order, ->{
joins("
INNER JOIN shotengai_orders ON
shotengai_snapshots.shotengai_order_id = shotengai_orders.id AND
shotengai_orders.status <> 'cart'
")
}
scope :in_cart, ->{
joins("
INNER JOIN shotengai_orders ON
shotengai_snapshots.shotengai_order_id = shotengai_orders.id AND
shotengai_orders.status = 'cart'
")
}
class << self
def inherited subclass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment