Changed Fields
Each entity tracks which of its fields has changed within the current unit of work/EntityManager
:
const a1 = em.load(Author, "1");
// Nothing has changed at first
expect(a1.changes.firstName.hasChanged).toBe(false);
// Now perform some business logic
a1.firstName = "a2";
// And the field shows up has changed
expect(a1.changes.firstName.hasChanged).toBe(true);
expect(a1.changes.firstName.originalValue).toEqual("a1");
The changes
API has three methods:
changes.firstName.hasChanged
- istrue
wheneverfirstName
has been set, either on a new entity or an existing entitychanges.firstName.hasUpdated
- istrue
only whenfirstName
has been changed on an existing entitychanges.firstName.originalValue
- is the original value, only for an existing entity
Audit Trails
Note the changes
API is only for the current in-memory changes being made to an entity, it's not an audit trail.
That said, Joist entities can be used with 3rd-party audit trail solutions like CyanAudit.