Module: Spree::Variants::NestedAttributes
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/workflows/spree/variants/nested_attributes.rb
Overview
Applies the nested data a variant write can carry: its option values, its prices and its stock levels. Shared by Spree::Variants::Create and ::Update so both write paths reconcile them the same way.
All three go through the model's own writers (set_option_value,
set_price, set_stock) rather than touching rows directly. That is
deliberate: set_price reuses the loaded prices association so a
response serialized in the same request sees the write, and set_stock
routes a count change through a stock movement so it lands in the
history like every other adjustment.
The three payloads do not share one nullability contract, because the records do not carry the same risk:
pricesis a full replacement — a currency missing from the payload loses its base price, and[]clears every one.stock_levelsis upsert-only. Dropping a warehouse from a payload must not silently destroy its stock: the count is a fact about a shelf, with a movement history behind it, and a partial payload is far likelier than an instruction to zero a warehouse.optionsis upsert-only, matching what the model has always done.