Represents nested fixtures that are synced after the parent.
The parent's ID is injected into each nested record via the foreign_key.
With a fixture module
defmodule MyApp.Seeds.Product do
use Sow, schema: MyApp.Product, keys: [:slug]
def records do
%{
slug: "premium",
variants: Sow.has_many(MyApp.Seeds.ProductVariant, foreign_key: :product_id)
}
end
endWith inline records
def records do
%{
slug: "premium",
variants: Sow.has_many_inline(
[
%{sku: "SMALL", name: "Small"},
%{sku: "LARGE", name: "Large"}
],
schema: MyApp.ProductVariant,
foreign_key: :product_id,
keys: [:product_id, :sku]
)
}
endDuring sync:
- Parent record is inserted/updated first
- Each nested record gets
product_id: parent.idinjected - Nested records are then synced