1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/// A **required** parent reference — the template field behind a non-null
/// foreign key.
///
/// The default is [`Auto`](Parent::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`](Parent::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.
// Manual, not `#[derive(Default)]`: the derive would bound `T: Default` and
// `Pk: Default`, which `Auto` does not need — and a template type without
// `Default` should still be usable as a `Parent`'s `T`.
/// An **optional** parent reference — the template field behind a nullable
/// foreign key.
///
/// The default is [`Absent`](OptionalParent::Absent): the column stays NULL,
/// because a factory should never invent rows the schema does not require. A
/// mod opts in with an existing row or a shaped template.
// Manual for the same no-spurious-bounds reason as `Parent`'s.