pub enum Parent<T, Pk> {
Auto,
Template(T),
Existing(Pk),
}Expand description
A required parent reference — the template field behind a non-null foreign key.
The default is Auto: at create time the parent’s own
default template is created first (recursively — a comment chains a post
chains a user) and the FK takes the created row’s key. That is the
schema-aware promise: create_many(&db, 10) on the deepest table makes
the whole chain exist, ten times over, each row with its own parents
(FactoryBot’s association semantics — share a parent by passing it in as
Existing instead).
build() (no database) fills the FK column only for Existing; Auto
and Template need a database to produce a key, so build() leaves the
column unset — recorded in the crate docs.
Variants§
Auto
Create the parent from its default template.
Template(T)
Create the parent from this shaped template — for_post(…).
Existing(Pk)
Use this already-existing row’s key — post(&p) / post_id(k).