Module: Spree::TypedAssociations
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- app/models/concerns/spree/typed_associations.rb
Overview
Shared flat-payload writer for has_many associations whose rows
are STI-typed and carry preferences/calculator metadata. Used by
Promotion (rules, actions) and PriceList (rules).
The wire shape is [{ type:, id?, preferences: {...}, calculator?: {...}, *_ids?: [...] }]
and the reconciliation is: existing rows update by id, new rows
build via find_by_api_type, missing rows destroy. Falls through
to AR's standard writer when assigned model instances (Rails
internals do this on association swap).
New-record parents defer the work into an @pending_<assoc> ivar
so child rows can FK to a persisted parent — the consumer model
is responsible for flushing those in an after_save.