Commit 9e1bb9af by ivan Lan

Add touch: true to belongs_to

parent d1cea924
......@@ -58,7 +58,8 @@ module Shotengai
self.model_name.singular.to_sym,
class_name: self.name,
optional: true,
foreign_key: :shotengai_order_id
foreign_key: :shotengai_order_id,
touch: true,
)
end
end
......
......@@ -25,7 +25,7 @@ module Shotengai
class << self
def inherited subclass
subclass.has_many :sub_catalogs, class_name: subclass.name, foreign_key: :super_catalog_id
subclass.belongs_to :super_catalog, class_name: subclass.name, optional: true
subclass.belongs_to :super_catalog, class_name: subclass.name, optional: true, touch: true
# subclass.instance_eval("def klass; #{subclass}; end")
super
end
......
......@@ -30,7 +30,7 @@ module Shotengai
class Order < ActiveRecord::Base
self.table_name = 'shotengai_orders'
belongs_to :buyer, polymorphic: true, optional: true
belongs_to :buyer, polymorphic: true, optional: true, touch: true
default_scope { where.not(status: 'cart') }
scope :status_is, ->(status) { where(status.blank?.! && { status: status }) }
......@@ -156,7 +156,8 @@ module Shotengai
self.model_name.singular.to_sym,
class_name: self.name,
optional: true,
foreign_key: :shotengai_order_id
foreign_key: :shotengai_order_id,
touch: true,
)
end
......
......@@ -30,7 +30,7 @@ module Shotengai
require 'acts-as-taggable-on'
self.table_name = 'shotengai_products'
belongs_to :manager, polymorphic: true, optional: true
belongs_to :manager, polymorphic: true, optional: true, touch: true
validate :check_spec, if: :spec
include AASM_DLC
......
......@@ -51,8 +51,8 @@ module Shotengai
def add_associations
# belongs to Product
@subclass.belongs_to :product, foreign_key: :shotengai_product_id, class_name: @product_name
@subclass.belongs_to @product_name.underscore.to_sym, foreign_key: :shotengai_product_id, class_name: @product_name
@subclass.belongs_to :product, foreign_key: :shotengai_product_id, class_name: @product_name, touch: true
@subclass.belongs_to @product_name.underscore.to_sym, foreign_key: :shotengai_product_id, class_name: @product_name, touch: true
# has many snapshot
@subclass.has_many :snapshots, class_name: "#{@product_name}Snapshot", foreign_key: :shotengai_series_id
end
......
......@@ -34,9 +34,9 @@ module Shotengai
validate :cannot_edit_if_order_is_paid
belongs_to :shotengai_order, foreign_key: :shotengai_order_id,
class_name: 'Shotengai::Order', optional: true
class_name: 'Shotengai::Order', optional: true, touch: true
belongs_to :shotengai_cart, foreign_key: :shotengai_order_id,
class_name: 'Shotengai::Cart', optional: true
class_name: 'Shotengai::Cart', optional: true, touch: true
scope :in_order, ->{
joins("
......@@ -58,8 +58,8 @@ module Shotengai
product_name = /^(.+)Snapshot/.match(subclass.name)[1]
series_name = "#{product_name}Series"
# belongs to Series
subclass.belongs_to :series, foreign_key: :shotengai_series_id, class_name: series_name
subclass.belongs_to series_name.underscore.to_sym, foreign_key: :shotengai_series_id, class_name: series_name
subclass.belongs_to :series, foreign_key: :shotengai_series_id, class_name: series_name, touch: true
subclass.belongs_to series_name.underscore.to_sym, foreign_key: :shotengai_series_id, class_name: series_name, touch: true
super
end
end
......@@ -85,7 +85,7 @@ module Shotengai
end
def cut_stock
self.series.cut_stock
self.series.cut_stock(self.count)
end
def meta
......
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