Skip to content

v3.6.0

Choose a tag to compare

@lehni lehni released this 11 Oct 16:20
· 319 commits to main since this release
63d5d64

What's new

  • The graph options of insertGraph() / upsertGraph() that take relation paths (relate, unrelate, insertMissing, update, noInsert, noUpdate, noDelete, noRelate, noUnrelate) also accept a relation expression in the same syntax as withGraphFetched(), e.g. noInsert: '*' or noDelete: '[pets, movies.reviews]'. Like the array, an expression only matches the relations at the end of the paths it names, so 'movies.reviews' doesn't match movies. '*' matches all relations at any depth, and recursive expressions like 'parent.^' every level of the recursion. Root models are never matched, so noInsert: '*' inserts new root models but no related ones. Aliases and empty expressions throw an error. #131

Fixes

  • upsertGraph() patches the related models of many-to-many relations by their id, and their extra properties in the join row by the ids of both ends. Until now these patches filtered by a subquery that joins the join table, and on MySQL, the patches of a graph upserted without a transaction deadlocked each other. The SQL of these patches changes. #135
  • The warning from 3.4.0 about owner models missing a join property skips the foreign key of a BelongsToOneRelation, unless it's part of the id. It's also missing when it was never set, e.g. on models returned by insert() or created with fromJson(), where no related model is the right result. A foreign key left out of a partial select() looks the same and no longer warns either. Join properties of all other relations still warn, including non-id columns. #132
  • relate(), $relatedQuery().insert() and insertGraph() / upsertGraph() inserting or relating models of many-to-many and has-one-through relations whose join table is also the related table throw an error, like unrelate() since 3.4.0. They inserted the join rows as new related rows, or failed with unique violations after inserting the related rows. #133
  • Recursive upserts of related models with children no longer warn about the unknown graph option options since 3.4.0

Other

  • Replace the custom build of lodash's cloneDeep() from 2018 with a small implementation, which $clone(), toJSON() and validation use to copy objects in model properties. It copies model data the same way, 2 to 4 times faster. Objects with a null prototype keep it instead of getting Object.prototype, BigInt64Array / BigUint64Array are copied instead of shared, and so are Buffers nested in objects, which shared their memory with the original before.
  • The parsers of relation expressions and JSON field expressions are generated with Peggy instead of PEG.js 0.10, with npm run build:parsers. Parse results and error messages are the same.
  • The example projects use current versions of their dependencies and need Node.js 20.17 or newer