0

I'm working on a project that uses the Solidus engine. However, we want to modify the models, specifically by creating new models that inherit from the engine's default models.

We chose to do this rather than completely overwriting the default models or doing the decorator, feeling that the decorator was too messy but overwriting would be too hard to maintain for updates, and so tried to find a middle ground, but regardless, this is the path we chose.

The issue is that in our modified model, when it is associated with another modified model, it is not saving associated data properly via the controllers.

As an example: Our Store::Product model (inherits from Spree::Product) has associations set as follows:

has_many :variants, :class_name => "Store::Products::Variant", :allow_destroy => true
accepts_nested_attributes_for :variants, :allow_destroy => true

When we send in variants_attributes in the form data, that form data doesn't get saved, even though: 1) if we call @product.variants.each {|v| v.save} in the Store::Product model after_save cb, it successfully saves all variants (indicating to me at least that there is nothing wrong with the data themselves or validations). 2) There are no errors on the associated variants' instance objects. 3) If we leave out the:

has_many :variants, :class_name => "Store::Products::Variant", :allow_destroy => true
accepts_nested_attributes_for :variants, :allow_destroy => true

(ie, just keep the default Spree::Variant model as the has_many for our Store::Product model), the form also works fine.

All that happens is the product's data gets saved and then it successfully redirects to wherever we set in the controller, as if nothing went wrong.

UPDATE: This is true ONLY for update calls (create works fine).

RyanQuey
  • 705
  • 1
  • 9
  • 29
  • Can you post the permitted parameters in the controller ? – Shiko Feb 12 '19 at 20:31
  • @shiko there's a whole bunch in this case, and some I can't post :) But the immediately relevant one is: `:variants_attributes => [:id, :sku, :cost_price, ...]`. There's some others in that array as well, for columns we added to the spree_variants table. Or was there something in particular you wanted to see? – RyanQuey Feb 14 '19 at 10:49

0 Answers0