Merge pull request #6633 from Matt-Yorkley/inverse-of

Adding inverse_of
This commit is contained in:
Maikel
2021-01-14 17:25:51 +11:00
committed by GitHub
14 changed files with 21 additions and 19 deletions

View File

@@ -5,7 +5,8 @@ module Spree
belongs_to :variant, class_name: "Spree::Variant"
belongs_to :order, class_name: "Spree::Order"
belongs_to :shipment, class_name: "Spree::Shipment"
belongs_to :return_authorization, class_name: "Spree::ReturnAuthorization"
belongs_to :return_authorization, class_name: "Spree::ReturnAuthorization",
inverse_of: :inventory_units
scope :backordered, -> { where state: 'backordered' }
scope :shipped, -> { where state: 'shipped' }

View File

@@ -41,7 +41,7 @@ module Spree
has_many :state_changes, as: :stateful
has_many :line_items, -> { order('created_at ASC') }, dependent: :destroy
has_many :payments, dependent: :destroy
has_many :return_authorizations, dependent: :destroy
has_many :return_authorizations, dependent: :destroy, inverse_of: :order
has_many :adjustments, -> { order "#{Spree::Adjustment.table_name}.created_at ASC" },
as: :adjustable,
dependent: :destroy

View File

@@ -2,9 +2,9 @@
module Spree
class ReturnAuthorization < ActiveRecord::Base
belongs_to :order, class_name: 'Spree::Order'
belongs_to :order, class_name: 'Spree::Order', inverse_of: :return_authorizations
has_many :inventory_units
has_many :inventory_units, inverse_of: :return_authorization
has_one :stock_location
before_create :generate_number
before_save :force_positive_amount

View File

@@ -4,7 +4,7 @@ module Spree
class ShippingCategory < ActiveRecord::Base
validates :name, presence: true
has_many :products
has_many :shipping_method_categories
has_many :shipping_method_categories, inverse_of: :shipping_method
has_many :shipping_methods, through: :shipping_method_categories
end
end

View File

@@ -12,7 +12,7 @@ module Spree
has_many :shipments
has_many :shipping_method_categories
has_many :shipping_categories, through: :shipping_method_categories
has_many :shipping_rates
has_many :shipping_rates, inverse_of: :shipping_method
has_many :distributor_shipping_methods
has_many :distributors, through: :distributor_shipping_methods,
class_name: 'Enterprise',

View File

@@ -3,6 +3,7 @@
module Spree
class ShippingMethodCategory < ActiveRecord::Base
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod'
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory'
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory',
inverse_of: :shipping_method_categories
end
end

View File

@@ -3,7 +3,7 @@
module Spree
class ShippingRate < ActiveRecord::Base
belongs_to :shipment, class_name: 'Spree::Shipment'
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod'
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
scope :frontend,
-> {

View File

@@ -4,7 +4,7 @@ module Spree
class StockItem < ActiveRecord::Base
acts_as_paranoid
belongs_to :stock_location, class_name: 'Spree::StockLocation'
belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :stock_items
belongs_to :variant, class_name: 'Spree::Variant'
has_many :stock_movements

View File

@@ -2,7 +2,7 @@
module Spree
class StockLocation < ActiveRecord::Base
has_many :stock_items, dependent: :delete_all
has_many :stock_items, dependent: :delete_all, inverse_of: :stock_location
has_many :stock_movements, through: :stock_items
belongs_to :state, class_name: 'Spree::State'

View File

@@ -5,7 +5,7 @@ module Spree
acts_as_paranoid
validates :name, presence: true, uniqueness: { scope: :deleted_at }
has_many :tax_rates, dependent: :destroy
has_many :tax_rates, dependent: :destroy, inverse_of: :tax_category
before_save :set_default_category

View File

@@ -16,8 +16,8 @@ module Spree
class TaxRate < ActiveRecord::Base
acts_as_paranoid
include Spree::Core::CalculatedAdjustments
belongs_to :zone, class_name: "Spree::Zone"
belongs_to :tax_category, class_name: "Spree::TaxCategory"
belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates
belongs_to :tax_category, class_name: "Spree::TaxCategory", inverse_of: :tax_rates
validates :amount, presence: true, numericality: true
validates :tax_category_id, presence: true

View File

@@ -18,10 +18,10 @@ module Spree
:tax_category_id, :shipping_category_id, :meta_description,
:meta_keywords, :tax_category, :shipping_category
has_many :inventory_units
has_many :line_items
has_many :inventory_units, inverse_of: :variant
has_many :line_items, inverse_of: :variant
has_many :stock_items, dependent: :destroy
has_many :stock_items, dependent: :destroy, inverse_of: :variant
has_many :stock_locations, through: :stock_items
has_many :stock_movements

View File

@@ -2,8 +2,8 @@
module Spree
class Zone < ActiveRecord::Base
has_many :zone_members, dependent: :destroy, class_name: "Spree::ZoneMember"
has_many :tax_rates, dependent: :destroy
has_many :zone_members, dependent: :destroy, class_name: "Spree::ZoneMember", inverse_of: :zone
has_many :tax_rates, dependent: :destroy, inverse_of: :zone
has_and_belongs_to_many :shipping_methods, join_table: 'spree_shipping_methods_zones'
validates :name, presence: true, uniqueness: true

View File

@@ -2,7 +2,7 @@
module Spree
class ZoneMember < ActiveRecord::Base
belongs_to :zone, class_name: 'Spree::Zone', counter_cache: true
belongs_to :zone, class_name: 'Spree::Zone', counter_cache: true, inverse_of: :zone_members
belongs_to :zoneable, polymorphic: true
def name