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 firstexpect(a1.changes.firstName.hasChanged).toBe(false);
// Now perform some business logica1.firstName = "a2";
// And the field shows up has changedexpect(a1.changes.firstName.hasChanged).toBe(true);expect(a1.changes.firstName.originalValue).toEqual("a1");The changes API has three methods:
changes.firstName.hasChanged- istruewheneverfirstNamehas been set, either on a new entity or an existing entitychanges.firstName.hasUpdated- istrueonly whenfirstNamehas been changed on an existing entitychanges.firstName.originalValue- is the original value, only for an existing entity
Audit Trails
Section titled “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.