Commit 17f8ea6e by ivan Lan

Improve sql in snapshot

parent cd3c849a
...@@ -39,21 +39,9 @@ module Shotengai ...@@ -39,21 +39,9 @@ module Shotengai
belongs_to :shotengai_cart, foreign_key: :shotengai_order_id, belongs_to :shotengai_cart, foreign_key: :shotengai_order_id,
class_name: 'Shotengai::Cart', optional: true, touch: true class_name: 'Shotengai::Cart', optional: true, touch: true
scope :in_order, ->{ scope :in_order, -> { joins(:shotengai_order).where.not(shotengai_orders: { status: 'cart'}) }
joins(" scope :in_cart, -> { joins(:shotengai_order).where(shotengai_orders: { status: 'cart'}) }
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 class << self
def inherited subclass def inherited subclass
product_name = /^(.+)Snapshot/.match(subclass.name)[1] product_name = /^(.+)Snapshot/.match(subclass.name)[1]
......
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