Model lifecycle reference¶
New and attached¶
Created through models.Users.New().
attached = true
exists = false
deleted = false
original = zero or construction baseline
dirty = assigned fields that differ from original
Save executes the configured insert query.
Persisted and clean¶
Created through retrieval or successful persistence.
Save performs no query.
Persisted and dirty¶
At least one current field differs from the original snapshot.
Save executes the configured update query. The initial implementation sends the complete configured update parameter structure rather than dynamically generating partial SQL.
Deleted¶
After a successful delete:
A second delete is idempotent. Save and Refresh return ErrDeletedModel.
Detached¶
A model without a persistence session is detached. Persistence and lazy loading return ErrDetachedModel.
Snapshot synchronization¶
After successful restore, insert, update, or refresh:
Reverting changes¶
The user becomes clean again because dirty state is derived from current-versus-original values, not from a permanent mutation flag.