Commit 9e1bb9af by ivan Lan

Add touch: true to belongs_to

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