From 3f13f8c57eec552958b0824918c016f45c6863bd Mon Sep 17 00:00:00 2001 From: andrea longhi Date: Tue, 21 Dec 2021 15:37:04 +0100 Subject: [PATCH] Reintroduce inverse_of: :product for variants association MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `inverse_of: :product` was moved to the `variants_including_master` association with 7c37093, but there shold be no problem in having this option specified in more than one association, in fact its removal is causing an issue and now the reference to the product changes is now lost for records in the `variants` association: p = Spree::Product.first v = p.variants.first m = p.variants_including_master.find_by(is_master: true) p.name = "Foobar" m.product.name # => "Foobar" v.product.name # => "Solidus T-Shirt" --- core/app/models/spree/product.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index bf837067df..011b25f852 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -45,6 +45,7 @@ class Product < Spree::Base has_many :variants, -> { where(is_master: false).order(:position) }, + inverse_of: :product, class_name: 'Spree::Variant' has_many :variants_including_master,