Associations are handled by giving specific values to foreign keys. Consider an Animal schema with a belongs_to association to a Species schema. That's represented by giving a value to the Animal's species_id foreign key:
params(name: "Bossie", species_id: ...)
Most likely, you don't want to give :species_id an explicit integer or GUID value. Instead, you want the database to create the Species row and use whatever value it gave as the primary key. That is accomplished as follows. Suppose you have a SpeciesExamples module containing a :bovine example:
defmodule SpeciesExamples do
use Template.EctoClassic.Insert
def create_test_data do
start(...) |>
workflow(:success,
bovine: [params(...)])
end
end
Then :bossie can be created "within" species :bovine like this:
At the moment, you can only fetch the primary key of another example, and that primary key must be named :id. All that's easily changed upon request.
The previous example showed how to refer to an example in a different module. If you want to use an example in the same module, you can abbreviate to just the example name:
Whenever an example is used, the very first step is to insert any other examples it depends on. Then those values are used to construct the examples params. If you trace the running of an example, you'll see those recursive creations. Here's an example of creating `:bossie