Changelog
4.4.4
Fixes
upsertGraph()doesn't run the$beforeUpdate()hooks of existing models that it only relates, e.g. through a join table or aBelongsToOneRelation, if they have props that aren't written to the database, like props that$formatDatabaseJson()orpickJsonSchemaPropertiesleave out. Their ids counted as changed, as there is no current model to compare them with, although nothing is written to their rowsdistinct()without columns makes the selected rows distinct, as in knex, e.g. inPerson.query().select('name').distinct(). Objection dropped it without an error. The query still selects all columns of its table by default, e.g.select distinct "persons".* from "persons"#557unrelate()only clears the columns of a key that aren't part of the id of their model, e.g. thetenantIdof multi-tenant keys like(tenantId, ownerCode), which it set tonullbefore.upsertGraph()does the same when it removes aBelongsToOneRelationrow, which it rejected before. If all columns of the key are part of the id, both throw, as only deleting the rows can remove the relation #561- MySQL: many-to-many
unrelate(), andpatch()with join table extras, work with keys that share a column, e.g. atenantIdin both keys of the join table. Since 3.7.0, they failed with "Operand should contain 4 column(s)" #565 insert()andrelate()through an owner model without a key, e.g. one that was never saved, whose insert didn't return an id, or whose key column isnull, throw an error that names the relation and the missing key, before any query runs. They failed with aTypeError, after inserting the related row in many-to-many relations, or updated nothing without an error inBelongsToOneRelationandBelongsToManyRelation. Anullkey in the owner madeHasManyRelationinsert and relate rows with anullforeign key #568- Relation writes that are filtered through
joinRelated()or its variants keep the joins: many-to-manyunrelate(),patch()anddelete(), belongs-to-oneunrelate(), and on MySQL has-manyrelate()andunrelate(). They lost them and failed with an unknown column #560 - MySQL:
patch()anddelete()with a subquery that joins the updated table under an alias, e.g.join('Person as owner', ...),join({ owner: 'Person' }, ...)orjoinRelated(), wrap the subquery, as they already did for joins without an alias. They failed with "You can't specify target table 'Person' for update in FROM clause" #564 upsertGraph()works for models whoseonBuild()hooks add where clauses to all queries, e.g. to leave out soft-deleted rows. It threw "upsertGraph query should contain no other query builder calls likefindById,where, …", as it checked for such calls after the hooks ran. Where clauses that a caller adds throughonBuild()on theupsertGraph()query itself are no longer rejected either, and have no effect #563- When the hook of one model rejects asynchronously and the hook of a later model throws, e.g. in
$beforeInsert(),$afterFind()or a relation'sbeforeInsert, or a traverser oftraverseAsync()does, the query rejects with the second error and handles the first. It was left as an unhandled rejection, which ends Node processes by default #566
4.4.3
Fixes
- Queries that mix
withGraphJoined()andwithGraphFetched()and select all columns of the root table, e.g. withselect('*')orselect('Person.*'), load the fetched relations again. Since 3.8.0,withGraphJoined()replaces the*with the table's columns, which made the query skip the build step ofwithGraphFetched(), so its relations were missing from the result without an error #2269 - An
onBuild()hook that removes operations, e.g. withclearSelect(), no longer makes the query skip building the operation after them, e.g. thewhereoffindById(), which made the query read, update or delete all rows
4.4.2
Fixes
upsertGraph()doesn't update models whose given props are unchanged apart from props that aren't written to the database, like props that$formatDatabaseJson()orpickJsonSchemaPropertiesleave out. They counted as changed, and the update ran the$beforeUpdate()hooks, which could still write e.g. timestamps #546
4.4.1
Changes
- Strict
insertGraph()andupsertGraph()resolve the settings of each relation path once instead of for every model and option, which speeds up large graphs with manyrelationsentries
4.4.0
Changes
- Add
Model.getGraphSettings(), which resolves the strict mode settings ofinsertGraph()orupsertGraph()for a relation path from the options of a call, with the same rules and defaults as the call itself #537
Fixes
- Strict
insertGraph()withadded: 'relate'throws aNotFoundErrorfor related models whose ids don't exist, before anything is written, likeupsertGraph()does. Since 4.3.0, it related them unchecked, writing keys that point to no row unless a foreign key constraint rejected them #538
4.3.0
Changes
- Add a
strictoption toinsertGraph()andupsertGraph()that makes graphs say what they mean. Options are given per relation, asrootandrelationssettings for the rows that a graph leaves out (removed), the rows with ids that aren't in their relation yet (added), the rows that stay (kept) and the new rows (created). In strict mode, they replace the per-path options likerelate,unrelateandnoDelete. See strict mode #429 - Strict graphs throw where other graphs skip or override data: for rows they don't write, for key props that contradict their relations, and for values they don't write that differ from the stored rows. Equal values pass, so fetched graphs can be sent back unchanged #429
- Strict
insertGraph()andupsertGraph()are atomic: they run in a transaction, their own unless the query already runs in one, so a database error halfway leaves nothing written. Hooks that run queries need to usecontext.transaction, or they wait for the transaction, and deadlock on SQLite #477
Fixes
- The typings of the
upsertGraph()options declarefetchStrategy, which TypeScript rejected since 1.6.4 added the option #531
4.2.0
Changes
patchAndFetch(),patchAndFetchById(),updateAndFetch()andupdateAndFetchById()throw when the same query is executed a second time, e.g. awaited twice. Since at least 1.0.0, the second run wrote back the row that the first one fetched, undoing other writes in between #519
Fixes
patchAndFetchById(),updateAndFetchById(),patchAndFetch()andupdateAndFetch()with an empty patch return the unchanged model if the row matches, andundefinedonly if it doesn't. Since 1.5.0 they always returnedundefined#517asFindQuery()in static after hooks runs theonBuildhooks of the query's context once. Since 2.0.0 it ran them a second time on the built write query, e.g. adding a join twice
4.1.0
Changes
- On PostgreSQL, json field expressions with a single key use
->and->>, e.g."props"->>'points'forref('props:points').castText(), so that expression indexes like((props->>'points'))match them. Deeper paths and keys that can be array indexes, like[0],0or-1, keep#>and#>>. This changes the generated SQL: an index built on the#>>'{points}'form no longer matches and needs to be rebuilt with->>#508
Fixes
- On PostgreSQL with
standard_conforming_stringsoff, json keys with backslashes in field expressions read the right values. Since 3.3.0 they read other keys or threw "malformed array literal" ref().castText()on a JSON path compares with string columns on MySQL with themysql2driver, e.g. in the joins of JSON relations. Since 4.0.0 it threw "Illegal mix of collations". Comparisons with string values,orderBy(),groupBy()anddistinct()on these values now compare bytes instead of using the connection's collation, so they're case-sensitive like on Postgres- In strict mode, editors suggest the columns of the model as keys of the objects that
where(),findOne()andhaving()take. Since 4.0.0 they suggested none
4.0.0
Upgrading from 3.x? The migration guide explains each breaking change and what to do about it.
Breaking changes
Packaging
- objection is an ES module package with an
exportsmap and no default export. Deep imports likeobjection/lib/...no longer work. See migration #140 - The typings are ES module declarations instead of
export =. See migration - Node 20.19 or newer is required (migration)
- Knex 3.3 or newer is required (migration) #95
- MySQL 8.0.17 or newer is required (migration) #292
- The typings require TypeScript 5.8 or newer (migration) #485
- The database error classes are objection's own, so
instanceofchecks against the classes of thedb-errorspackage no longer match. See migration - Errors of knex's
better-sqlite3client are wrapped in objection's error classes, e.g.UniqueViolationError, instead of reaching you asSqliteError - Model files given as paths are loaded with
require(), so ES module model files need to export the model class as default or as their only class, and can't use top-level await. See migration
upsertGraph() and insertGraph()
Both are rewritten. They now write a graph in the order that its rows depend on each other, and reject graphs that contradict themselves before writing anything.
- They write in far fewer queries, e.g. one delete per relation, so static hooks get several models at once. A custom
insert()that forwards arrays toinsertGraph()now recurses forever. See migration - They throw for
onConflict(),ignore()andmerge(), which 3.x ignored (migration) #2156 - They throw for unknown options, and for option values of the wrong type even when no model uses them (migration) #84
insertGraph()throws for new models below models that it relates (migration) #217- A graph that gives the same row two different values for a column, or two rows to one
HasOneRelation, throwsInvalidGraph. A many-to-many pair gets one join row. See migration - A
#refor#ref{}to a new model that the graph doesn't insert throwsInvalidGraph, and so do cycles of#ref{}values. See migration #53 #427 - Below a model that
noInsertskips, only the models that a#refpoints to are kept. See migration #369 - Validation error paths of array input start with the index, e.g.
[1].pets[0].name, and the returned models no longer contain#id,#refor other markers. See migration - Custom relation classes that extend
Relationdirectly need akeySidegetter that says where their keys are stored:'owner','related'or'join'. See migration upsertGraph()writes models below related models together with the rest of the graph, instead of in nested calls at the end. See migration #427upsertGraph()moves rows to their new owners before it deletes, so a row moved out of a deleted parent is kept. Swapping rows on a unique key now needs theunrelateoption. See migration #214upsertGraph()checks that the models it relates exist, and throws aNotFoundErrorbefore writing anything. See migration #372upsertGraph()doesn't patch models that didn't change, so their update hooks don't run, and throws aNotFoundErrorwhen a row it updates is gone. See migration #214 #415- When a graph changes a row's key,
upsertGraph()writes the new key first, and uses it wherever the row appears in the graph. See migration #427 #428 #491 upsertGraph()sets the owner's foreign key tonullbefore it deletes aBelongsToOneRelationmodel, also when the owner's schema doesn't allownull. See migration #212upsertGraph()keeps the currentHasOneRelationmodel when the graph gives a different model marked with#unrelateor#delete, or a replacement thatnoInsertornoRelateskips. See migration #261upsertGraph()relates aBelongsToOneRelationmodel that only gives its key, likepet: { code: 'c1' }, without looking it up, and throwsInvalidGraphif it also gives other props or relations
Hooks
- The
resultof staticafter*hooks has the shape that the query returns: a model,undefined, a number or an array.asArray()turns it into an array. See migration #66 #210 - The static
after*hooks run last, afterfirst()and the fetch of*AndFetch(), andrunAfter()callbacks run after them. See migration #66 - Find hooks only run for queries that actually run, so no longer for the input models of
upsertGraph(), andbeforeFindno longer for models thatfetchGraph()already has. See migration #66 withGraphFetched()uses the models thatafterFindreturns, so the hook can filter or reorder them, andwithGraphJoined()callsafterFindtoo. See migration #1963
Queries
skipUndefined()is removed, andundefinedvalues passed towhere()and the other query methods throw. See migration #53findById(1).orWhere(…)can no longer return other rows: the id condition gets its own parentheses. See migration #271- Aggregates like
count()select only their alias, and queries that load relations add the join columns they need, which grouped queries must group by. See migration #111 - Writes with
returning()on a to-one$relatedQuery()resolve to one model orundefined, not an array. See migration #53 offset()in updates and deletes throws, and so doesorderBy()withlimit()in a MySQL delete. See migration #286 #235- Many-to-many patches with join table extras run in one query, which needs SQL Server 2016 or newer. See migration #287
idColumn = undefinedmeans that the model has no primary key, likenull#129
Relations
limit(),offset()andfirst()inwithGraphFetched()modifiers apply to each parent, not to all of them together. SetlimitPerParent: falsefor the 3.x behaviour. See migration #127 #429- Relation expressions that name a relation twice (migration) or have anything after
*or^(migration) throw #131 #221 - Fetching a relation throws when the models lack the columns it joins on, instead of finding nothing. See migration #1832 #2258 #114
$setRelated()and$appendRelated()update the foreign keys to match. See migration #2001unrelate()of aBelongsToOneRelationrespects the relation'smodify/filter, instead of unrelating all owners #234
JSON
- On PostgreSQL, JSON attributes are no longer parsed a second time, so JSON stored in
textcolumns stays a string. SetjsonColumnFormat = 'text'for those. See migration #205 snakeCaseMappers()no longer converts JSON keys in field expressions like'data:someKey'. See migration #1089insert()andupdate()reject field expression keys like'meta:color'. Usepatch(). See migration #160- JSON field expressions and the
whereJson*()methods throw on SQL Server and Oracle, instead of warning. See migration #113 - On MySQL, the casts of
ref()andval()use MySQL's own types, and objects and arrays inval()are JSON values on MySQL and SQLite. See migration #276
Typings
- Custom query builders declare one
RebindTypeinstead of five*QueryBuilderTypemembers. See migration #125 insert(),patch(),update()andrelate()reject relation properties, which they ignore at runtime. See migration #53toJSON()returns plain JSON types instead of model instances. See migration #2380$relatedQuery()of to-one relations may resolve toundefined. See migration #2355- Smaller type changes:
RelateQueryBuilder(migration), readonlyjsonSchema(migration) andvirtualAttributes, no$properties inModelObject(migration),relate().returning()rows (migration), no internal helper types (migration), noallowMarkers(migration), anddistinctOn()takes only columns,raw()andref()#16 #319 #433 #84
Features and fixes
Packaging
wrapError()is exported, to wrap errors of the database driver that don't come from objection's queries
upsertGraph() and insertGraph()
#refsets the foreign key in aHasManyRelationorHasOneRelation#311#ref{}works in foreign keys that the relation also sets #1378, and reads values that the graph fills in, like the key of an inserted model #356- A many-to-many
#refwrites only its own join table extras, instead of copying those of the model it points to - A row can move out of a
HasOneRelationwhile a new row takes its place #368 #398 - Keys that the database generates, like a uuid that isn't the id, are fetched before rows that join through them are written #853
- New models get the keys of their parents that the graph leaves out, instead of
NULL - With
relateandnoUpdate,HasManyRelationandHasOneRelationmodels are related, instead of silently left alone #53 - Foreign keys in a JSON path, like
pet.data:sitterId, are written without losing the other values of the column #488 - A failed graph waits for its running queries before it rejects, so a transaction rolls back after them #335
- Large graphs stay under the number of values that a database can bind in one query
- Several models without properties can be inserted on PostgreSQL #1694
- Rows whose foreign keys point to each other are patched one after the other, which avoids deadlocks on MySQL #385
upsertGraphAndFetch()applies the modifiers and aliases ofwithGraphFetched()#839- Models returned by
upsertGraph()write all their props when patched later #371 - Loaded many-to-many models no longer carry internal
objectiontmpjoin*aliases, e.g. in theitemsof delete hooks #370 - The error for
upsertGraph()queries with other query builder calls mentions$query(), which adds such a call too #1168 - A
#refat the root, or a graph that changes part of a composite id, throwsInvalidGraphbefore anything is written, andBigIntids throw on SQLite, which can't bind them
Hooks
- The hooks of
relate()andunrelate()get therelationand its owners #66 cancelQuery()with a single row inbeforeInsertis used as the inserted model, instead of being ignored #66
Queries
insert()of several models works on SQLite 3.35 or newer, and on all databases when every model has its id- Many-to-many patches with join table extras and
limit()can order by join table columns, and patch the right join rows on MySQL and SQL Server #161 #360 asFindQuery()in the hooks of these patches works for more rows than SQL Server can bind #287
Relations
- New
BelongsToManyRelation, for owners that hold an array of related ids, e.g.post.tagIds. See relations #2667 modifyJoin()changes theONclause of the joins ofjoinRelated()andwithGraphJoined()#1975
JSON
- JSON field expressions and the
whereJson*()methods work on MySQL and SQLite, exceptwhereJsonSupersetOf()andwhereJsonSubsetOf()on SQLite. See JSON queries #276 patch()with field expression keys writes intoNULLcolumns, and still works when the query is built twice #53insert()on SQLite stores arrays as JSON, instead of'[object Object]'
Typings
- Strict mode, opt-in with
TypeConfig { strict: true }, checks the columns, values, relations and modifiers of queries against your models. See models #16 #431 #432 FromModel<typeof Model>derives a model's properties from itsjsonSchemaandrelationMappings. See models #16 #430patch()andmerge()accept field expression keys like'address:street'- Faster type checking, and fixes in
ModelProps,ModelRelations,ModelClass<M>andwhereIn()
Other
- The tests run on vitest, and the examples and docs use ES modules
3.9.1
Fixes
insertGraph()andupsertGraph()reject only after the queries they already started have finished, so a transaction is rolled back after them. Before, rows of these queries could be committed after the rollback on SQLite #336upsertGraph()sets the foreign key of a model that a#refrelates into aHasManyRelationorHasOneRelation. Before, the row was left without it, and the id of the owner could be cleared #311upsertGraph()withrelateandnoUpdatewrites the foreign keys of models that it relates through aHasManyRelationorHasOneRelation, like it does forBelongsToOneRelationandManyToManyRelation, instead of leaving them unrelated without an error, as it did since 1.5.0 #355upsertGraph()resolves a#ref{}to a value of an existing model, e.g. a foreign key that an inserted related model gives it, once the graph has filled it in. Before, it read the old value, e.g.undefined#356, #378upsertGraph()rejects a graph with cyclic references before it writes anything. Before, it still ran the deletes of the rows that the graph leaves out after the rejection, which deleted them without a transaction and failed after the rollback of one, since 1.5.0 #379- A many-to-many
patch()/update()with join table extras andlimit()on MySQL and SQL Server writes the extras to the join rows of the related rows that the limit picks when the relation joins through a related column other than the id, instead of to the join rows that refer to other rows by these ids, as it did since 3.8.0 #360
3.9.0
Fixes
- Behaviour change:
upsertGraph()replacing the row of aBelongsToOneRelation, e.g.{ id: 1, pet: { id: 2 } }, points the owner to the new row before it deletes the old one. The static delete hooks of these deletes get norelationoritemsin their context, as the rows are deleted by id. Before, the old row was deleted first: with aNOT NULLforeign key andON DELETE CASCADE, the database deleted the owner andupsertGraph()still succeeded, and foreign keys withoutON DELETEaction failed. A new row that repeats a unique value of the row it replaces now fails, as both exist at the same time: pass the id of the old row to update it instead. WhennoInsertornoRelateskips the replacement, the current row and the owner's reference are kept. - Behaviour change:
upsertGraph()removing the row of aBelongsToOneRelationwithpet: nullor#deletesets the owner's foreign key tonullbefore it deletes the row if the owner'sjsonSchemaallowsnullfor it (intype,anyOf,oneOfor withnullable: true). Before, the row was deleted first: withON DELETE CASCADEthe database deleted the owner, and foreign keys withoutON DELETEaction failed. The owner is now patched, also withON DELETE SET NULL, so its update hooks run (e.g. writingupdatedAt), and the static delete hooks of these deletes, like those of replaced rows, get norelationoritemsin their context. Without a nullable schema for the key, the row is still deleted first and the owner's reference is left to the database. #212 - Behaviour change:
upsertGraph()no longer deletes a row that is missing in one place of the graph if the same graph relates or updates it in another place. The row is unrelated from its old place instead, so rows can be moved between parents in one call, also below related models. #214 - Behaviour change:
upsertGraph()with a#unrelateor#deletemarker on aBelongsToOneRelationmodel that isn't the currently related one keeps the current one, as the marked model is ignored. Before, the current row was deleted without clearing the owner's foreign key. #213 - Behaviour change:
insertGraph()andupsertGraph()no longer insert the related models of models thatnoInsertskips, unless a#refpoints to them. These were inserted without foreign keys. #215 insertGraph()logs a warning when it ignores new models below related models. This will throw in objection 4.0. UseupsertGraph()or a separate query to insert them. #217- Behaviour change: the graph options reject
*and^in brackets with other relations, likechildren.[pets, ^], instead of never matching them #221 - The
#refand#dbRefmarkers are removed from the results ofinsertGraph()andupsertGraph(), also from models they skip #221 upsertGraph()no longer throws "model (id=…) is not a child of model (id=…)" for children with ids below nodes related through arelatepath option #220$relatedQuery().insertGraph()with several models on many-to-many relations inserts the join rows on SQLite and MySQL, where it failed #219$relatedQuery().insertGraph()on aBelongsToOneRelationrelates the inserted row to the owner #216- Behaviour change:
deleteById(),patchById()andupdateById()also keep their id condition in its own where group, which the 3.8.0 notes already claimed for "the other*ByIdmethods":deleteById(1).where(a).orWhere(b)runsid = 1 and (a or b)instead ofid = 1 and a or b, which deleted other rows. AfindById()added by the user stays in the user's where group, also infindById(1).patch(…). #232 - Behaviour change: a many-to-many
patch()/update()that only changes join table extras returns the number of related rows whose join rows it updated, instead of 0. The staticafterUpdatehooks receive this number as theirresultinstead of 0.patchAndFetchById()with only extras returns the patched row instead ofundefined. #235 - Behaviour change: on SQL Server, a many-to-many
patch()/update()with join table extras applieslimit(),offset()andorderBy()to the related rows it picks, and only updates their join rows, as on MySQL. Before, the limit applied to each batch of related rows, all join rows were updated, and anorderBy()with the limit failed with a syntax error. Withlimit().offset()but noorderBy()it now throws, as SQL Server rejectsOFFSETwithoutORDER BY, where the offset was ignored before. #233 - Many-to-many
patch()/update()with join table extras select the related ids straight from their filter query, unlesslimit()oroffset()picks the related rows on MySQL or SQL Server. Postgres could plan the previous query as a nested loop that ran for minutes #161 - On MySQL,
delete()with bothorderBy()andlimit()warns that the order has no effect, as knex leaves it out of the statement. This will throw in objection 4.0. #235 - Behaviour change: query properties like
raw(),ref()and subqueries given to a model instance are no longer written again once their keys are given a value, by assignment,$set(),$setJson()or a write that fetched the value.$setJson()keeps the query properties of earlier calls,$setJson(modelInstance)drops them for the keys the instance has, values that objection sets itself (e.g. foreign keys set byinsertGraph()and$relatedQuery().insert()) beat a query property for the same key, values that$beforeInsert()/$beforeUpdate()set for keys given as query properties are removed from the instance after the hooks, as the query properties are written instead, and schema defaults no longer appear on the model or intoJSON()for keys given as query properties. #202 raw()and other query properties assigned to json attributes in$beforeInsert()and$beforeUpdate()are written instead of their serialized objects #203- Behaviour change:
pickJsonSchemaPropertieskeeps field expression keys like'meta:a'whose json column is in the schema, sopatch(),update()andupsertGraph()write them instead of silently dropping them.insert()no longer silently drops such keys either: they reach the database and fail as they do withoutpickJsonSchemaProperties. Keys only found onObject.prototype(like'toString') are no longer picked.upsertGraph()no longer selects field expression keys as columns. #204 - Behaviour change: a
patch(),update()ormerge()that sets both a json column and a field expression into it throws aValidationError, also when a model instance holds both, instead of dropping the field expression or failing with an SQL error #206 - Behaviour change: patches and the field expressions of
update()are validated without therequiredproperties of schemas referenced by$id, like the ones added inonCreateAjv(), which regressed in 3.8.0. Whole values for such properties in patches are validated withoutrequiredtoo, like localdefinitions. #207 onConflict().merge()with a json field expression key no longer fails with an ambiguous column on Postgres.merge({ 'meta:b': ref('meta:a') })is still ambiguous: qualify the reference with the table, e.g.ref('items.meta:a'). #260- Behaviour change:
hasSelection()andfindSelection()treat a table name without schema as the schema-qualified table, sowithGraphJoined()no longer throws for selections likepersons.idof a model with atableNamelikepublic.persons, a regression in 3.8.0, and replaces itspersons.*selections #226 - Behaviour change:
withGraphJoined()tells apart rows whose ids are Buffers, e.g. binary UUIDs, andwithGraphJoined()/withGraphFetched()tell apart keys whose dates differ only in milliseconds, composite keys whose strings contain commas, and string ids that contain/or., also inupsertGraph(). Dates are keyed by their time, so aDateand a number with the same epoch milliseconds match, e.g.Dateids passed tofetchGraph()and the numbers SQLite returns for them. #222 #223 resultSize()and thetotalofpage()andrange()respectdistinctOn()withwithGraphJoined()on Postgres, also on joined columns #224limitPerParentlimits the related items when the relation key is a JSON field #225withGraphFetched()with thelimitPerParentoption works for related models with a schema-qualifiedtableName, also when the order names the schema #265- Behaviour change: when SQL Server reports several errors for one statement, e.g. for
offset()withoutorderBy(), objection throws aDBErrorwith all their messages, instead of the driver'sAggregateErrorwith an empty message, which is kept asnativeError update(),patch()anddelete()warn aboutoffset(), as knex leaves it out there, and on SQL Server the limit too. This will throw an error in objection 4.0. #286
Types
- Custom query builders that override
withGraph()compile again, also with TypeScript 7, which broke in 3.7.0 with therelate().returning()typings
Docs
withGraphFetched()doesn't assign related rows whose keys only match by collation: by case or accents on MySQL, by case or trailing spaces on SQL Server #227upsertGraph()matches ids by their exact value, and how to normalize uuids given in a different case #221
3.8.0
What's new
- The
limitPerParentgraph option applieslimit(),offset()andfirst()of relations loaded withwithGraphFetched()per parent instead of to all parents together, e.g.withGraphFetched('pets(latest)', { limitPerParent: true }). Withpage()/range()the relation query is limited as before. On MySQL before 8, relations with a limit are fetched with one query per parent.withGraphJoined()ignores the option and warns about it. #127 #429
Fixes
- Behaviour change:
update()validates field expression keys like'meta:color'likepatch()does since 3.3.0: the written parts are validated against the json column's schema, including$refs, without itsrequired, while the rest of the object is validated normally. The json column counts as present and doesn't get itsdefault. Before, the keys were validated as top-level properties: invalid values passed,additionalProperties: falserejected the keys, a required json column counted as missing, and itsdefaultreplaced the whole stored value. #160 - Behaviour change: keys containing
:that the schema declares inproperties, e.g.'ns:name', are normal properties and columns: validated as properties and written to their column bypatch(),update()andmerge(). Before,patch()(since 3.3.0) andupdate()/fromJson()treated them as field expressions and wrote them as JSON paths. Properties that only$beforeValidate()declares are still treated as field expressions. #160 - Behaviour change:
insertGraph()throws aValidationErrorof typeInvalidGraphfor#unrelate/#deletemarkers also withallowMarkers: true, where 3.7.0 skipped the marked models: an insert has nothing to unrelate or delete.allowMarkersstays in theInsertGraphOptionstypings until 4.0, deprecated and without effect. #2410 - Behaviour change: a root model marked with
#unrelateor#deletegets the error that the markers can only be used for related models, inupsertGraph()andinsertGraph(), also withoutallowMarkers. #164 - Behaviour change:
upsertGraph()withnoUpdate,noDelete,noUnrelateandinsertMissingruns as an upsert like any otherupsertGraph()call. Models that already exist are left alone instead of failing with duplicate key errors, and markers allowed withallowMarkerstake effect. OnlyinsertGraph()runs as an insert. - Behaviour change: many-to-many
patch()/update()with join table extras select the ids of the matching related rows first, patch the join rows, and then the related rows by these ids, in batches of 500 values. A filter on a column that the patch changes, e.g..patch({ name: 'renamed', role: 'new' }).where('movies.name', 'old'), left the join rows unchanged. These patches run several statements, so use a transaction if they need to be atomic. #161 - On MySQL,
limit()/offset()of many-to-manypatch()/update()with join table extras pick the related rows to update, and only their join rows are updated. Before, all matching join rows were updated. Other databases ignore a limit in updates, as before. #161 - Behaviour change:
asFindQuery()in static hooks always runs the find query and returns the affected rows. It returned the value the query was resolved with, e.g.0for a patch with nothing to set, or the value ofresolve()/cancelQuery(), and threwTypeError: related.some is not a functionfor many-to-many patches that only change join table extras. asFindQuery()in static hooks of many-to-manypatchAndFetchById()/updateAndFetchById()keeps the query's filters- Behaviour change: the id condition of
$query()and ofpatchAndFetchById(),updateAndFetchById()and the other*ByIdmethods gets its own where group, so a user'sorWhere()can't get around it:$query().patch(…).orWhere(b)runsid = 1 and (b)instead ofid = 1 or b. The where groups are built when the SQL is generated, soasFindQuery()in static hooks no longer drops or repeats where clauses of relation queries, which regressed in 3.3.0. #2191 - Behaviour change:
withGraphJoined()selects the root table's columns instead of*, so the columns of joined tables no longer land on the root models under their plain names.distinct('*')keeps itsdistinct. distinctOn()withwithGraphJoined(),withGraphFetched()andjoinRelated(): its columns were treated as selected, so the other columns were missing from the models, and joined relations could fail with "column does not exist".- Behaviour change:
withGraphJoined()throws when the root query selects a different column under a name it selects itself, e.g. a joined table's column without an alias likeselect('Person.*', 'pets.id'),select('pets.*'),ref('Person.age').as('name')or'Person.name as id', and raw SQL, subqueries or aggregates under the name of an id column it needs to build the graph. Before, SQL Server returned arrays of values and the other databases silently kept one of them, sometimes grouping the root models by the wrong id. Raw SQL, subqueries and aggregates under other names replace the column. Select such columns under a different name. - Selections are matched after
wrapIdentifiermapping (knexSnakeCaseMappers()) for column names and aliases too, sowithGraphFetched()no longer selects a relation column a second time and strips it from the result when it's selected under its snake_case name - Behaviour change:
resultSize()withwithGraphJoined()throwsmodel … has no idColumnfor models without a primary key if the joined relations include a to-many relation, as the root models can't be counted without ids. Since 3.3.0 it counted the joined rows instead, or failed on MySQL. With only to-one relations, the rows are counted. #164 - On SQL Server, the order of a relation's
modifyor anonBuildhook is left out of the subqueries of many-to-many modify queries,withGraphJoined()andjoinRelated(), includingthrough.modify, and out ofupdate()/patch()queries, unless they have a limit. SQL Server rejects these orders. Other databases are unchanged. #167 - On SQL Server,
update(),patch()anddelete()of aliased tables go through a common table expression, as SQL Server can't alias the table of these statements - Behaviour change: on SQL Server, constraint, not-null and data errors are thrown as
DBErrorand its subclasses (UniqueViolationError,ForeignKeyViolationError,NotNullViolationError,CheckViolationError,DataError), with the tedious error asnativeError, like on the other databases. Readerr.nativeError.numberinstead oferr.number. This also makes the fix for primary key violations from 3.7.0 work with knex. #2688 - The warning about duplicate relations in relation expressions like
'[a.b, a.c]'says that only the last one is used and that it will throw in objection 4.0, instead of announcing an error in objection 2.0 #164 - Behaviour change: all warnings objection logs start with
[objection], and each is logged once #164 - The errors for mixing
withGraphJoined()andwithGraphFetched()quote relation names with double quotes like other error messages
Docs
- What
relate().returning()returns on each database, and which relations accept an array of ids onBuildKnex(): calls on the objection builder that map to knex methods are applied- The typings require TypeScript 5.1, and CI checks them with it. With TypeScript 5.0, methods of custom query builders like
firstWithName() { return this.where(...).first(); }are implicitlyanywithout a return type annotation.
Other
- The knex peer dependency is
>=2.3.0 <4, the versions objection is tested with #95 - CI runs the integration tests on SQL Server #163
3.7.0
Security
- Behaviour change: the
#unrelateand#deletemarkers need the newallowMarkers: trueoption in bothinsertGraph()andupsertGraph(), like#refneedsallowRefs. Without it, a marked model throws aValidationErrorof typeInvalidGraph, also ininsertGraph(), which silently skipped marked models before. The markers come from the graph data and take precedence over thenoUnrelate/noDeleteoptions, so graph data from a request body could unrelate or delete related rows that these options were meant to protect. WithallowMarkers: true, the markers work as in 3.6.0. #2410
Fixes
- Behaviour change: many-to-many
unrelate()/patch()identify the join rows to modify with a correlatedEXISTSsubquery, instead of row ids (ctidon Postgres,_rowid_on SQLite), the values of all columns (MySQL) or the related ids (MSSQL). The generated SQL changes. This fixes join tables that are Postgres views,through.modifyfilters (on Postgres they failed withcolumn "tableoid" does not exist, on SQLite they modified other join rows), MySQL join rows withFLOATorDATETIME(6)values that don't survive a round trip through JavaScript, and on MSSQL the filters on the join table, which modified all join rows of the matching related rows. On Postgres, SQLite and MSSQL, join rows that only differ in their extras are told apart, so only the matching one changes. On MySQL, the owner and related keys of the matching join rows are fetched with the subquery first, and the join rows are then modified by these keys, as MySQL doesn't let a statement read the table it modifies, e.g. through filters that read the join table or triggers on it. The keys can't tell apart join rows that only differ in their extras, like before 3.3.0. #1853 - Behaviour change:
upsertGraph()upserts the subgraphs of related models that it relates recursively. There, arrays of relation paths in theupdateandnoUpdateoptions match the full relation path from the root of the graph, like relation expressions since 3.6.0, so they also apply to the root models of the subgraph, e.g.noUpdate: ['movies']to the related movies. Before, they were matched against the relation paths from the root of the subgraph. The other options have no effect on the root models of a subgraph. #131 - Behaviour change:
runAfter()hooks in the queries of relations loaded withwithGraphFetched()no longer see the join columns that objection selects internally, like the other queries since 3.3.0. Hooks that read these columns getundefined. #45 - A
through.modelClassjoin model withidColumnreturningnullis no longer changed to use the related join columns as its id #2305 - Warn once when the
joinOperationoption is passed towithGraphFetched()or for fetched relations ofwithGraph(), where it is ignored #2125 - The warning from 3.4.1 about owner join properties holding arrays also covers many-to-many relations #2667
whereInComposite()with multiple columns and a subquery works on SQLite, as a row value comparison, instead of throwingwhereInComposite()with multiple columns and a subquery works on MSSQL- Many-to-many
through.modifyfilters are kept for model classes bound withbindKnex() insertGraph()/upsertGraph()throw the error about cyclic references for a#refcycle through owners without a primary key, instead of failing to patch the deferred foreign key by id #2305- Behaviour change: with
none(), or when a query is resolved withresolve()in a hook, patches and updates no longer modify the extras of many-to-many join rows or the instance of$query(), andBelongsToOneRelationdeletes no longer clear the foreign keys of the owners. These were updated although nothing was written. #2184 $clone(),toJSON()and validation copy objects with a writableSymbol.toStringTag, e.g. decimal.js numbers, instead of sharing them, which regressed in 3.6.0. Built-ins likeURLare still shared, like in lodash'scloneDeep().- Patch validation keeps boolean subschemas like
properties: { b: false }. They were dropped, so patches passed that the schema forbids. - Patch validation no longer validates field expression keys with numeric parts like
'tags:0'against object schemas, which rejected patches of array elements - Required properties given as query properties, e.g.
raw(), failed validation with an error about a missing schema when the schema uses$refto the schema of another model class #2199 - On Postgres, a backslash in front of a
?in a JSON field expression key is kept, which knex dropped #2077 - On MySQL, subqueries of the updated or deleted table are also wrapped in where groups and join clauses, which failed with
ER_UPDATE_TABLE_USED resultSize()and thetotalofpage()withwithGraphJoined()keep the selections thatgroupBy()andhaving()refer to by alias #2329- Relation expressions no longer mistake inherited object properties for relations, e.g. when merging graph expressions or parsing a relation named
constructor#63 $clone()no longer prints Node'sBuffer()deprecation warning (DEP0005)
Types
fetchGraph<Person>()with only the model type argument compiles again, without narrowingPartialModelObjectaccepts partial objects for nullable to-one relations #2190- Behaviour change:
snakeCaseMappers()andknexSnakeCaseMappers()take separate option types,SnakeCaseMappersOptionsandKnexSnakeCaseMappersOptions, withpreserveJsonKeysonly on the former, soknexSnakeCaseMappers({ preserveJsonKeys: true })no longer compiles. The option never had an effect there. The shared options areSnakeCaseOptions. - The rows of
relate().returning()are typed asany, andreturning()accepts multiple columns #2044
Docs
- Graph option expressions can't name a relation together with relations below it, or repeat a relation like
'[movies.reviews, movies.actors]'#131 - Shared validators throw for different schemas with the same
$id - The typings require TypeScript 5.0 since 3.3.0
- Workarounds for the
withGraphnarrowing with reassignments and generic helpers insert()andpatch()ignore relation data
Other
- Behaviour change: remove the
mapNestedKeysoption ofknexSnakeCaseMappers()andknexIdentifierMapping()that 3.5.0 added. It also converted the keys of JSON columns that the driver returns parsed. Results are converted one level deep again, like before 3.5.0. TheKnexIdentifierMappingOptionstype is removed too. #2273
3.6.0
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 aswithGraphFetched(), e.g.noInsert: '*'ornoDelete: '[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 matchmovies.'*'matches all relations at any depth, and recursive expressions like'parent.^'every level of the recursion. Root models are never matched, sonoInsert: '*'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 byinsert()or created withfromJson(), where no related model is the right result. A foreign key left out of a partialselect()looks the same and no longer warns either. Join properties of all other relations still warn, including non-id columns. #132 relate(),$relatedQuery().insert()andinsertGraph()/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, likeunrelate()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
optionssince 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 anullprototype keep it instead of gettingObject.prototype,BigInt64Array/BigUint64Arrayare 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
3.5.0
What's new
- Add the
mapNestedKeysoption toknexSnakeCaseMappers()andknexIdentifierMapping(), which also converts the keys of objects nested one level down, e.g. the column names in the rows of knex'snestTables: trueoption on MySQL:knexSnakeCaseMappers({ mapNestedKeys: true })#2273 - The relation mapping's
beforeInsert(model, context, owner)hook receives the owner model as a third argument. WithinsertGraph()/upsertGraph()it's the parent object from the input graph, which may not be inserted yet, and it'sundefinedwhen the query was started from ids or several owners. #2240
Types
- Add the opt-in
TypedRelationMappings<M>helper: used withsatisfiesonrelationMappings, it checks that the mappings use relation properties of the model, a relation type matching their cardinality, and the rightmodelClass#16 - Add
Generated<T>to mark columns the database fills in, e.g.id!: Generated<number>, and theInsertable<M>/InsertableGraph<M>types for insert data, which leave them optional #16 - Add
isOneToOne()to theRelationtypings and docs. It's the safe way to check for relations to a single model, asHasOneRelationandHasOneThroughRelationextend the many-relations.
3.4.1
Fixes
- Select aliased aggregates like
count('* as n'),count('id', { as: 'n' })andcount({ n: 'id' })inwithGraphJoined()modifiers. They were treated as selecting all columns, or were missing from the result. Unaliased aggregates are left out, since their column name differs between databases. #2219 - JSON field expressions (
ref('col:path'),'col:path'keys in patches) and thewhereJson*()methods warn once on databases other than Postgres, where they generate invalid or silently wrong SQL. MySQL, for example, reads#>as a comment. On MySQL,whereJsonSupersetOf(column, value)/whereJsonSubsetOf(column, value)with a plain column and a JSON object or array are passed on to knex, which supports them there. #276 - Fix the infinite recursion in
andWhereJsonNotSupersetOf() - The warnings about missing join properties from 3.4.0 also cover
ManyToManyRelationandHasOneThroughRelation: owner models missing a join property, and related models that come back without the owner join column, e.g. stripped by$parseDatabaseJson(). #1832, #2258 - Warn once when a relation's owner join property holds an array, e.g. a JSON array of keys, which isn't supported and silently fetched no related models. Use a
ManyToManyRelationthrough a join table instead. #2667
3.4.0
What's new
- Support models without a primary key: return
nullfromidColumn, e.g. for join table models. Methods that need an identifier, likefindById(),deleteById()and$query(), throw an error. #2305
Fixes
insertGraph()/upsertGraph()withrelate: truesilently droppedHasManyRelation/HasOneRelationchildren whose composite id contains the foreign key, and deleted the existing ones without inserting them again #2544- Required properties given as query properties, e.g.
raw(),val(),ref()or subqueries, failed validation #2199 upsertGraph()treated JSON arrays and objects as unchanged when they loosely equal the current value, e.g.falseand[]. Behaviour change: these values are now patched. #1874- Many-to-many and has-one-through relations whose join table is also the related table failed with SQL errors in
withGraphFetched(),$relatedQuery()andrelatedQuery().unrelate()and patching join table extras on such relations throw an error instead of modifying the wrong rows. #1803 - Patch validation rejected valid patches when an
anyOf/oneOfoption only consisted ofrequired, which 3.3.0 didn't cover yet #1681 - Throw
UniqueViolationErrorfor primary key violations on MSSQL #2688 $fetchGraph()/fetchGraph()/$relatedQuery()warn once when owner models are missing a join property, e.g. an id left out of a partialselect(). The relation silently came back empty. Since 3.6.0, the foreign keys ofBelongsToOneRelationowners no longer warn, see #132. #1832withGraphJoined()checks column aliases against the identifier length limit of the database (MySQL 256, MSSQL 128, SQLite none) instead of always the 63 of Postgres, and the error points to theminimizeoption. The limit isn't configurable. #2242withGraphFetched()/$fetchGraph()warn once when related models are missing a join property, e.g. snake_case relation mappings withknexSnakeCaseMappers(). They were silently dropped. #2258insertGraph()/upsertGraph()warn once per unknown option, e.g. a misspellednoInset. The option is ignored, and will throw in 4.0. #84
Types
- Add the
onlyoption tofrom(),table()andinto(), e.g. for PostgresONLY#2182
Docs
first()doesn't limit the related items per parent inmodifyGraph()#1647runAfter()in the queries of fetched relations can't replace the related models #2647page()andrange()need anorderBy()with a unique tiebreaker to avoid repeated or skipped rows #2575- Typing model properties with a merged interface #2237
- The
throughmapping of relations whose join table is also the related table #1803
Other
- Breaking for old knex: the knex peer dependency is
>=2.3.0instead of>=1.0.1. Some fixes of 3.3.0 don't work with older knex versions. CI now also tests knex 2.3.0. Part of #95 - Tests no longer use bluebird, lodash and uuid
3.3.0
Security
- Escape keys in JSON field expressions. A
?in a key used inref(), a patch or update with field expression keys, or thewhereJson*methods was read by knex as a binding placeholder #2077, and a'broke out of the SQL string literal, allowing SQL injection when keys come from user input.
What's new
withGraphFetched()/withGraphJoined()narrow the result types: fetched relations become required on the result. Generic helpers with an explicitQBreturn type needwithGraphFetched<string>(). #25 Behaviour change: this also breaks variables declared withletthat are later assigned an unnarrowed query, helpers generic over the model type that returnQueryBuilder<M>, and explicit type arguments likePerson.fetchGraph<Person>()(fixed in 3.7.0). Annotate the variable, or usewithGraphFetched<string>().- Add
withGraph()with algorithm-agnostic merging, andisJoinChildQuery()#63 - Add
patchById()andupdateById()#1415 insertGraph()/upsertGraph()resolve cyclic#refdependencies by deferringBelongsToOneforeign keys. Graphs that threw before now succeed, and the deferred foreign keys are written with onepatch()per owner model, which runs its update hooks. #1482- Add a
preserveJsonKeysoption tosnakeCaseMappers()to map only the column part of field expressions #1089 - Support empty keys in JSON field expressions, e.g.
col:[""]#2680. Behaviour change:col:[""]andcol:['']used to refer to a key consisting of the two quote characters,col:[a,b]to the patha.binstead of the keya,b, and spaces around keys in brackets were trimmed. whereJson*methods acceptref(),val(),raw()and subqueries on the right side- Pass
returning()options, e.g.includeTriggerModifications, on to knex #2309
Fixes
- Group the user's where clauses when adding a relation's owner condition.
$relatedQuery(...).where(a).orWhere(b).delete()/patch()affected other owners' rows, and finds returned them. #2191, #1909 findByIds([])/whereInComposite()with an empty array and composite ids produced invalid SQL, and matched every row on SQLite #1914onConflict().ignore(): inserted rows were assigned to the wrong models,$setDatabaseJsoncould crash, andinsertAndFetch()fetched undefined ids. Behaviour change: on SQLite this usesRETURNING, which needs SQLite 3.35 or newer, and it throws when it can't match the returned rows to the models, e.g. with ids generated by the database. Ignored models are still returned, with their input values. #2320, #2597, #2661asFindQuery()in many-to-many update and delete hooks lost its filters #2266- Patch validation:
notschemas stay intact #1681, and nestedrequiredis also stripped for nullable and untyped objects, extending the 3.1.2 fix #1664 resultSize()and thetotalofpage()count root models instead of joined rows withwithGraphJoined()#2143, #2329. The limit ofpage()still applies to the joined rows.- Keep aliased subquery and raw selections in
withGraphJoined()modifiers #2365 - Map column names in
whereJson*methods withknexSnakeCaseMappers. Behaviour change: column names given in database format are mapped again, which changes some of them, e.g.data_2withunderscoreBeforeDigits. - Match
table.*selections through knex identifier mapping #2288 - Use the keys of modified
graphExpressionObject()results #2793 - Track internally selected columns on the query builder, so
runAfter()hooks of the query never see them. The queries of relations loaded withwithGraphFetched()still do. #45 - Behaviour change: many-to-many
unrelate()/patch()only modify the join rows matching the filters, not all join rows of the matching related rows #1853. The generated SQL of these operations changes. On MySQL, the matching join rows are fetched in a separate query, which avoidsER_UPDATE_TABLE_USED("You can't specify target table … for update in FROM clause") #2127 andER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRGwhen a trigger on the join table modifies the related table #2406, andunrelate()returns0instead of[]when nothing matches. Ported from #2406. - Behaviour change:
asFindQuery()in hooks no longer applies therunAfter()callbacks of the original query, including those ofthrowIfNotFound()andtraverse(), and returns[]instead of[undefined]for afindById()that finds nothing #2093 - Behaviour change: field expression keys in patch objects, e.g.
'meta:a.b', are validated against the nested schema of the JSON column. Patches like{ 'meta:b': value }no longer fail withadditionalProperties: false, but patches that passed before can fail the nested schema #1666 - Behaviour change: the
joinOperationoption ofwithGraphJoined()applies per call, no longer to all relations of the query #2125 - Behaviour change:
withGraphJoined()throws when it can't identify rows, instead of silently merging them #2737. It still needs a primary key on every model, and models without one throw a clear error #2748. insertGraph()/upsertGraph()warn whenonConflict(),ignore()ormerge()is used. The clause is ignored, and will throw in 4.0. #2156
Types
- Breaking for TypeScript < 5.0: the typings use
consttype parameters, so they need TypeScript 5.0 or newer.skipLibCheckdoesn't help, as older versions can't parse them. - Export the db-errors classes as types #2499
Docs
- The docs moved to VitePress and are hosted at ditojs.github.io/objection
- Document
relatedFindQueryMutates/relatedInsertQueryMutates#2356 - Document running code after a transaction commits #2582
Other
- Update knex to 3.3 in development, which fixes inverted bindings in
delete()withjoinRelated()#2799
Thanks to @falkenhawk and Marcin L for the many-to-many work in #2406, @kapouer for #2680 and @cesumilo for #2625, which led to preserveJsonKeys.
3.2.0
Objection is now maintained at ditojs/objection.
What's new
- Support mixing
withGraphJoined()andwithGraphFetched()in the same query. Before, the last method called silently decided the algorithm for all relations. A top-level relation can only be loaded with one of them. Behaviour change: loading the same top-level relation with both, e.g.withGraphFetched('pets').withGraphJoined('pets.toys'), throws. Before, all relations were joined. #2269 - Add
none()to make a query match no rows #2184 upsertGraph(): mark individual related models with#unrelateor#delete#2410. Since 3.7.0, the markers need theallowMarkers: trueoption.- Return rows from
relate()withreturning()#2044 - Apply
select()to the fetch query ofupdateAndFetch(),patchAndFetch()and theirByIdvariants #1938 - Add a
noDoubleUnderscoresoption to the snake case mappers #2805 - Pass
formatoptions fromtoJSON()/$toJson()to$formatJson()of the model and all nested models #2033 - Support
$defsin JSON schemas #2576
Fixes
- Behaviour change: throw when
for()is used outside ofrelatedQuery(). It was silently ignored before, soModel.query().for(1).delete()deleted every row of the table. #2185 - Behaviour change: throw when
for()is called after a write method on arelatedQuery(). Before,update(),patch()anddelete()silently did nothing, andinsert()andrelate()wroteNULLforeign keys. - Fix validators being shared between models with the same
uniqueTag()but different schemas. Part of #2540 - Fix
orderBy()with refs and raws as array items #2252 - Clear an
orderByadded at build time, e.g. by a relation'smodify, from theresultSize()andpage()count query #2747 - Support
Model.ref()references in relation join mappings #1873 - Reference the bare column in JSON where methods when no JSON path is given, so Postgres can use GIN indexes #2008
- Fix subqueries in join builders on MySQL (
parentQuery.isUpdate is not a function) #2407 - Make
union()deduplicate regardless of array size #2811 - Serialize relation modifiers and aliases before the recursion marker in
RelationExpression.toString()#2812
Types
- Fix
first()infinite type recursion in custom query builder methods #2637 PartialModelObjectaccepts partial model data for nested relations, so inserting objects typed with data-only interfaces type-checks #2190- Keep custom query builder types after
throwIfNotFound() - Add a
QueryBuilderconstructor typing for custom query builders #2306 - Allow
nulland readonly arrays foridColumn, readonly arrays forjsonAttributes. Code that reads them needs to handle these types. Models without a primary key are supported at runtime since 3.4.0. #2693, #2745 - Allow
bigintvalues in where methods #2318 - Support object joins,
limit()/offset()withskipBinding, and aliased aggregates. Part of #2189 - Fix the
tableNameFor(),tableRefFor()andaliasFor()typings #2790 - Add
knexIdentifierMapping#1947 - Add
tableName(),tableRef()andemptyInstance()toQueryBuilder#2792, #2794 - Add the column list overload of
with()#2749 - Fix generic static
thisforquery(),fromJson()andfetchGraph()#2700
Docs
- Document what
afterInsert()receives asresult#2342 - Document that
withGraphJoined()requires a primary key #2748 - Document the
skipUndefined()deprecation #2149 - Use
declarefor the query builder type properties in the custom query builder and plugin recipes, which fail with TS2612 on ES2022+ targets - Fix the koa-ts example typings #2361
- Clarify
whereNotColumn()#2808
Other
- Drop Node 14 from CI, since knex 3 requires Node 16+. Objection's
enginesstill include Node 14, but it's no longer tested.
Thanks to everyone whose pull requests made it into this release: @amit-meshbey, @androvonx95, @bilalakbar, @Bolt4243, @cesumilo, @falkenhawk, @geeksilva97, @IlyaSemenov, @kapouer, @kartikdp, @LiahMartens, @max-kahnt-keylight, @nickbouldien, @nickfuryoc, @ralcorta and @salisbury-espinosa.
3.1.5
What's new
- Types: Fix generic static
this#2533 - Types: Add
fromRawto `FromSelector regex #2628 - Types: Fix argument types of
onConflict()#2635 - Types: Make
trxoptional forModel.transaction(trx, cb)#2694
3.1.4
What's new
- Fix
upsertGraph()$beforeUpdate()calls on empty relates #2605 - Don't call
onError()with internal exceptions #2603 - Remove docs and typings for nonexistent
$pick() - Make
$omitFromJson()+$omitFromDatabaseJson()compatible with old$omit()syntax
3.1.3
What's new
What's new
- Patch Validator: Prevent recursion on inner properties #2520
3.1.2
What's new
- Patch Validator: Prevent recursion on inner properties #2520
3.1.1
What's new
- Only add Ajv formats if they weren't added in user-land already #2482
3.1.0
What's new
- Support
$beforeUpdate()mutations inupsertGraph()#2233 - Remove deprecated
$afterGet()hook #2477 - Drop support for Node v12 #2478
3.0.5
What's new
3.0.4
What's new
- Fixes #2447
3.0.3
What's new
- Fixes #1673
- Fixes #1957
- Fixes #2105
- Fixes #2132
- Fixes #2251
- Fixes #2262
- Fixes #2271
- Fixes #2277
- Fixes #2308
- Fixes #2311
- Fixes #2311
- Fixes #2311
- Fixes #2332
- Fixes #2337
- Fixes #2372
- Fixes #2379
- Fixes #2383
- Fixes #2399
- Fixes #2404
- Fixes #2405
- Fixes #2408
- Fixes #2409
- Fixes #2423
3.0.2
What's new
- Fixes #1356
- Fixes #1957
- Fixes #2192
- Fixes #2247
- Fixes #2307
- Fixes #2308
- Fixes #2311
- Fixes #2323
- Fixes #2337
- Fixes #2362
3.0.1
What's new
3.0.0
What's new
- Fixes #1986
- Fixes #1987
- Fixes #1954
- Fixes #1993
- Fixes #1688
- Fixes #1651
- Fixes #2135
- Fixes #1936
- Fixes #1905
- Fixes #1997
- Fixes #2024
Breaking changes
See the migration guide.
2.2.10
What's new
- Add
modelClassproperty forValidationErrorandNotFoundError.
2.2.9
What's new
- Add
noWaitquery builder method.
2.2.8
What's new
2.2.7
What's new
QueryBuilder.castTocan now be used to cast query results to any typescript type.
2.2.6
What's new
- Fixes #1964
2.2.5
What's new
- Fixes #1855
2.2.4
What's new
- Add support for onConflict, merge and ignore knex methods.
2.2.2
What's new
2.2.1
What's new
2.2.0
What's new
2.1.4
What's new
- Fixes #1750
2.1.3
What's new
- Add
underscoreBetweenUppercaseLettersoption for snake case mappers. #1676
2.1.2
What's new
- Fix
startTransactiontypings.
2.1.1
What's new
- Fixes #1489
2.1.0
What's new
Changelog
2.0.10
What's new
- Fixes #1630
2.0.9
What's new
- Fixes #1606
2.0.8
What's new
- Fixes #1627
2.0.7
What's new
- Fixes #1607
2.0.6
What's new
- Fixes #1603
2.0.5
What's new
- Fixes
upsertGraphbug where composite keys were not selected correctly. See the fix here.
2.0.4
What's new
- New
skipFetchedoption forfetchGraphand$fetchGraph
2.0.3
What's new
2.0.0
What's new
Cleaner and more consistent API. A lot of methods have been renamed, removed combined and cleaned up. Most of the old methods still exist, but print a deprecation warning when first used. Some examples:
eager->withGraphFetchedjoinEager->withGraphJoined- removed
eagerAlgorithm(you must explicitly use eitherwithGraphFetchedorwithGraphJoined) - merged
allowEager,allowInsertandallowUpsertinto one methodallowGraph $loadRelated->$fetchGraphjoinRelation->joinRelated$relatedQueryno longer mutates the receiving model instances
New static hook API. The old instance hooks are still around.
relatedQuerycan now be used for more than just subqueries. See the examples here.modifiers can now take arguments and are a lot more useful. See this recipe for more info.
Objection now uses the db-errors library by default to wrap the database errors.
insertMissingupsertGraphoption now works as expected withrelate: true: items that are not found in the database are inserted.Brand new typings written from scratch with many improvements and finally a support for custom query builders
A bunch of improvements and bug fixes for
upsertGraph, including a huge speedup in some cases due to less data fetching.A brand new fn helper for calling SQL functions.
Objection now uses native promises instead of bluebird.
Objection is now leaner as we dropped a bunch of dependencies like
bluebirdandlodash.In addition to all of this, a huge number of bugs has been squashed!
Breaking changes
See the migration guide.
1.6.10
- Fixes #1455
1.6.9
- Revert fix for #1089. It was causing more bugs than it fixed. #1089 will be addressed in 2.0.
- Typings updates
1.6.8
- Fix #1287
1.6.7
- A bunch of regression bug fixes.
1.6.3
- Fixes: #1227
1.6.2
- Add
asmethod forrawmaking it possible to userawexpressions injoinEagermodifiers (as long as you give names to your raw expressions usingas).
1.6.1
- Fix some very rare upsertGraph edge cases.
1.6.0
Add
Model.traverseAsyncandmodelInstance.$traverseAsyncmethods.Fixes: #842 and #1205. This bug is about subqueries "inheriting" parent query table name and alias. This bug has been around a long time and there is a small chance that people have started accidentally or on purpose use it as a feature. If you get weird reference errors from subqueries (relation not found, table not found etc.) you may need to explicitly give an alias or use
fromin your subqueries after this update. This is a borderline breaking change, but since 2.0 is still pretty far away, I wanted to get this out faster. If I'm wrong and people are heavily depending on this bug, I'll revert the change.Fixes: #1215
Fixes: #1206
1.5.3
What's new
- Fixes #1204
1.5.1
What's new
- Relations are now loaded lazily #1202
relationMappings.modelClasscan now be a function that returns a model class.
1.5.0
What's new
- fix #1131
- fix #1114
- fix #1185
- fix #1109
- fix #1110
- add eagerObject and eagerModifiers accessors to QueryBuilder.
- complete rewrite of
insertGraphandupsertGraphcode. The rewrite brought a bunch of small performance optimizations and makes future development easier. No breaking changes. - Chaining
returning('*')toinsertGraphorupsertGraphnow propagates the call to all insert, update and delete operations. - Code using objectio can now be transpilsed to ES5. No need to add babel workarounds anymore.
1.4.0
What's new
1.3.0
What's new
- Use
objection.rawinstead ofknex.rawinModel.raw. #1077 - Allow modifiers (namedFilters) to be used in
modifyEagertoo. - Add
underscoreBeforeDigitsoption for snake case converters. #1025 - fix #1074
- Typing fixes
1.2.3
What's new
1.2.2
What's new
- Improve reference cycle detection in
upsertGraph
1.2.1
What's new
- fix #1009
1.2.0
What's new
- fix #919
- fix #964
- Add
aliasFormethod to public API - Prevent bluebird warnings
- UPPER_SNAKE_CASE support for
snakeCaseMappersandknexSnakeCaseMappers
1.1.10
What's new
- Nothing! the npm release was somehow borked. This was just a rerelease of 1.1.9.
1.1.9
What's new
- fix #782
1.1.8
What's new
- fix #909
1.1.7
What's new
- fix #884
1.1.6
What's new
- Add typings for fetchTableMetadata, tableMetadata and onbuildknex
1.1.5
What's new
- Make Model.fetchTableMetadata and Model.tableMetadata methods public. #871
- Add onBuildKnex query builder hook. #807
1.1.4
What's new
- fix subquery bug causing incompatibility with knex 0.14.5 and sqlite3
1.1.3
What's new
- fix regression in 1.1.2 (sorry about this) #869
1.1.2
What's new
1.1.1
What's new
- fix #865
- fix bug where the static
Model.relatedQuerydidn't use the relation name as an alias for the table. This may break code if you have explicitly referenced the subquery table. #859
1.1.0
What's new
- Optional object notation for relation expressions.
- fix #855
- fix #858
1.0.1
What's new
- Added public Relation.joinModelClass accessor
- Don't call
returningon sqlite (prevents a warning message added in knex 0.14.4) - fix #844
- Small documentation updates
- Small typing fixes end updates
1.0.0 🎉
What's new
- The static
relatedQuerymethod. - New reflection methods:
isFind,isInsert,isUpdate,isDelete,isRelate,isUnrelate,hasWheres,hasSelects,hasEager,has.clear.columnNameToPropertyName,propertyNameToColumnName. ManyToManyextras now work consistently in queries and filters. #760
Breaking changes
modelInstance.$query().delete().returning(something)now returns a single instance instead of an array. #659Node 6.0.0 is now the minimum. Objection will not work on node < 6.0.0.
ValidationErroroverhaul. This is a big one, so read this carefully! There are three things to check when you migrate to 1.0:- The
createValidationErrorandValidationErrorinterfaces have changed. If you have overridden thecreateValidationErrormethod in your project, or you create customValidationErrorinstances you need migrate to the interfaces. - The model validation errors (jsonSchema violations) have remained pretty much the same but there are couple of differences. Before, the keys of
error.datawere property names even when a nested object in a graph failed a validation. Now the keys for nested validation errors are key paths likefoo.bar[2].spam. Another tiny difference is the order of validation errors for each key inerror.data. Let's say a propertyspamfailed for your model anderror.data.spamcontains an array of objects that describe the failures. Before, the first failed validation was the last item in the array, now it is the first item. - All
ValidationErrorsnow have atypefield. Before allValidationErrorsbut the model validation errors (errors like "invalid relation expression", or "cyclic model graph") had no type, and could only be identified based on the existence of some weird key inerror.data. Theerror.datais now removed from those errors and thetypeshould be used instead. The message from the data is now stored inerror.message.
- The
Removed deprecated methods
whereRef,whereJsonFieldandwhereJsonEquals. Therefhelper can be used to replace thewhereRefcalls.refandlitcan be used to replace the removed json methods.ManyToManyextras now work consistently in queries and filters. #760. This is not a breaking change per se, but can cause some queries to fail with a "ambiguous identifier" error because the join table is now joined in places where it previously wasn't. You need to explicitly specify the table for those failing columns usingTable.theColumnsyntax.
Changes
isFindQueryis renamed toisFindand deprecated.
0.9.4
What's new
0.9.3
What's new
- Add beforeInsert hook for relations. #649 #19
- Add
relatedFindQueryMutatesandrelatedInsertQueryMutatesconfigs as well as$setRelatedand$appendRelatedhelpers. #599 - Fixed #648
0.9.2
What's new
- Fix regression:
fromfails with a subquery.
0.9.1
What's new
castTomethod for setting the model class of query result rows.onErrorQueryBuildermethod.knexSnakeCaseMappersandsnakeCaseMappersfor snake_case to camelCase conversions.
0.9.0
What's new
- Relations can now be defined using keys inside JSON columns. See the examples here.
lithelper function #275- Fixes for
upsertGraphwhen using composite keys. #517 - Added
noDelete,noUpdate,noInsert,noRelateandnoUnrelateoptions forupsertGraph. See UpsertGraphOptions docs for more info. insertGraphnow accepts an options object just likeupsertGraph.relateoption can be used instead of#dbRef. #586
Breaking changes
Instance update/patch with
returningnow return a single object instead of an array. #423Because of the support for JSON relations the
Relationclass has changed a bit.
0.8.8
What's new
- Typing updates: #489 #487
- Improve
resultSizemethod. #213 - Avoid unnecessary updates in upsertGraph #480
0.8.7
What's new
throwIfNotFoundnow also throws when update or delete doesn't change any rows.mixinandcomposehelpers for applying multiple plugins. #475 #473- Typing updates #474 #479
upsertGraphnow validates patched models correctly. #477
0.8.6
What's new
- Finally: the first version of
upsertGraphmethod! Please open issues about bugs, WTFs and missing features. - Strip readonly virtual properties in fromJson & friends #432
- Fixed #439
0.8.5
What's new
- Add
Model.useLimitInFirstconfiguration flag.
0.8.4
What's new
- New shorthand methods
joinEager,naiveEager,mergeJoinEagerandmergeNaiveEager. - New shorthand method
findOne - New reflection method
isFindQuery - ManyToMany extra properties can now be updated #413
0.8.3
What's new
NaiveEagerAlogrithm- Aliases in relation expressions #402
- New lazily evaluated
rawfunction. #275
0.8.2
What's new
Model.namedFiltersobject for defining shared filters that can be used by name in eager expressions.- Full support for views and table aliases in eager, join, joinRelation etc. #181
- Fix
bindTransactionbug withManyToManyRelationjunction tables #395
0.8.1
What's new
throwIfNotFoundmethod for making empty query results throw an exception.- fix error when passing model instance to a
wheremethod. #387
0.8.0
What's new
- All query methods now call
Model.queryto create aQueryBuilderinstance #346 - Objection is no longer transpiled. One of the implications is that you can use a github link in package.json to test experimental versions.
countcan now be called without arguments #364- A new
getRelationsmethod for plugin development and other reflection greatness.
Breaking changes
Old model definition
function Person() {
Model.apply(this, arguments);
}
Model.extend(Person);
Person.tableName = 'Person';
Person.prototype.fullName = function () {
return this.firstName + ' ' + this.lastName;
};
// More static and prototype methods.Easiest way to migrate to
classandextendskeywords
class Person extends Model {}
Person.tableName = 'Person';
Person.prototype.fullName = function () {
return this.firstName + ' ' + this.lastName;
};
// More static and prototype methods.Support for node versions below 4.0.0 has been removed. With it the support for legacy class inheritance using
Model.extendmethod has also been removed. This means that you need to change your model definitions to use theclassandextendskeywords. To achieve this with the minimum amount of changes you can simply swap the constructor function andModel.extendto a class definition. You can still define all static and prototype methods and properties the old way. See the example on the right -->Note that this also affects Babel transpilation. You cannot (or need to) use
babel-plugin-transform-es2015-classesanymore. See the ESNext example project as an example of how to setup babel.The default value of
pickJsonSchemaPropertieswas changed tofalse. Before, all properties that were not listed injsonSchemawere removed beforeinsert,patchorupdate(ifjsonSchmawas defined). Starting from this version you need to explicitly set the value totrue. You may have been used this feature by accident. If you have weird problems after the update, try settingobjection.Model.pickJsonSchemaProperties = true;to see if it helps.relateandunrelatemethods now return the result of the underlying query (patchin case ofHasManyRelation,HasOneRelation, andBelongsToOneRelation.insertotherwise). Before the method input was always returned.Model.RelatedQueryBuilderis removed.Model.QueryBuilderis now used to create all query builders for the model. This only affects you if you have defined custom query builders.
0.7.12
What's new
- fix #345
0.7.11
What's new
0.7.10
What's new
- fix bugs that prevented using
$relatedQueryandeagertogether withJoinEagerAlgorithm - typing updates
0.7.9
What's new
joinRelationnow acceptsRelationExpressionsand can join multiple and nested relations.
0.7.6
What's new
rangeandpagemethods now use a window function and only generate one query on postgresql #62- fix MSSQL 2100 parameter limit in eager queries #311
0.7.5
What's new
0.7.4
What's new
- automatically select columns needed for relations #309
- fix an issue where
$formatJsonwas called insideinsertGraph#326
0.7.3
What's new
- fix #325
- fix an issue where
selecthad to be used in addition todistinctin some cases
0.7.2
What's new
HasOneThroughRelationrelation type.
0.7.1
What's new
- fix
JoinEagerAlgorithmNPE bug
0.7.0
What's new
jsonSchemawithoutpropertiesnow works. #205relationMappingscan now be a function. #227- many to many extras can now be aliased. #223
- zero values are now allowed in relation columns. #228
- active transaction can now be accessed in
$before/$afterhooks throughqueryContext.transactionproperty. - Validation can now be easily modified through a new
Validatorinterface. #241 #199 - fix a
JoinEagerproblem where an empty result for a relation caused the following relations to be empty. #292 ref(fieldExpression)syntax to reduce need for knex.raw and updating single attribute inside JSON column. #270- mergeEager method.
Breaking changes
$relatedQuerynow returns a single model instead of an array for belongsToOne and hasOne relations. #155- identifier of a model can now be updated. Be careful with this one! Before if you forgot a wrong id in an
update/patchoperation, it would simply get ignored. Now the id is also updated just like any other column #100 Table.*is now selected by default in all queries instead of*. This will break some join queries that don't have an explicit select clause. #161ValidationError.datais now an object including, for each key, a list of errors with context info. #283
0.6.2
What's new
relationMappingscan now be a function #227
0.6.1
What's new
- fix bug #205
0.6.0
What's new
- Eager loading can now be done using joins and zero extra queries. See
eagerAlgorithm,defaultEagerAlgorithmandeagerfor more info. #refin graph inserts can now contain extra properties for many-to-many relations #156#dbRefcan now be used to refer to existing rows from ainsertWithRelatedgraph.modelPathsattribute for cleaner way to point to models in relationMappings.pickJsonSchemaPropertiesconfig parameter #110insertGraphAndFetchwithinsertWithRelatedAndFetchalias. #172- Added
$beforeDeleteand$afterDeletehooks #112 - Old values can now be accessed from
$beforeUpdate,$afterUpdate,$beforeValidateand$afterValidatehooks #185 - Support length property #168
- Make sure operations are executed in the order they are called #180
- Fetch nothing if the
whereclauses hit no rows inupdate/patchAndFetchByIdmethods #189 - Lots of performance tweaks.
$loadRelatedandloadRelatednow return aQueryBuilder.
Breaking changes
Undefined values as query method arguments now throw an exception. Before they were just silently ignored and for example
delete().where('id', undefined)caused the entire table to be deleted. skipUndefined method can be called for a query builder to handle the undefined values the old way.Deprecated method
dumpSqlis now removed.$loadRelatedandloadRelatednow return aQueryBuilder. This may break your code is some rare cases where you have called a non-standard promise method likereflectfor the return value of these functions.
0.5.5
What's new
0.5.4
What's new
- bugfix: insertWithRelated now works with
additionalProperties = falseinjsonSchema - Add updateAndFetch and patchAndFetch methods for
$query - bugfix: afterGet was not called for nested models in eager query
- Use ajv instad of tv4 for json schema validation
0.5.3
What's new
- ES6 promise compatibility fixes.
0.5.1
What's new
- $afterGet hook.
0.5.0
What's new
- joinRelation family of query builder methods.
HasOneRelationfor creating inverse one-to-one relations.- Relations have been renamed
OneToOneRelation-->BelongsToOneRelation,OneToManyRelation-->HasManyRelation. The old names work, but have been deprecated. - withSchema now works as expected and sets the schema of all queries executed by the query builder the method is called for.
- filterEager method for better eager query filtering.
- extra properties feature for selecting/inserting columns from/to the join table in many-to-many relations.
- Eager query recursion depth can be controlled like so:
parent.^5.
0.4.0
What's new
- Query context feature. See #51 and these docs for more info.
- Composite key support.
- findById, deleteById, whereComposite and whereInComposite query builder methods.
Breaking changes
There shouldn't be any major breaking changes. We moved from ES5 to ES7 + babel in this version so there are big changes in the codebase. If something comes up, please open an issue.
There are a few known corner cases that may break:
You can now define a model for the join table of
ManyToManyrelations inrelationMappings. This is optional, but may be needed if you already have a model for aManyToManyrelation and you usesnake_casetocamelCaseconversion for the column names. See the documentation on the through property of relationMappings.The repo no longer contains the actual built javascript. Only the ES7 code that is transpiled when the code is published to npm. Therefore you can no longer specify a git hash to package.json to use for example the HEAD version. We will start to publish alpha and RC versions to npm when something new and experimental is added to the library.
0.3.3
What's new
- fix regression: QueryBuilder.from is broken.
0.3.2
What's new
- Improved relation expression whitespace handling.
0.3.1
What's new
whereJson*methods can now be used inside functions given towheremethods.- Added multiple missing knex methods to
QueryBuilder.
0.3.0
What's new
- insertWithRelated method for inserting model trees
- insertAndFetch, updateAndFetchById and patchAndFetchById helper methods
- Filters for eager expressions
- New alternative way to use transactions
- Many performance updates related to cloning, serializing and deserializing model trees.
Breaking changes
- QueryBuilder methods
update,patchanddeletenow return the number of affected rows. The new methodsupdateAndFetchByIdandpatchAndFetchByIdmay help with the migration modelInstance.$query()instance method now returns a single model instead of an array- Removed
Model.generateId()method.$beforeInsertcan be used instead
0.2.8
What's new
- ES6 inheritance support
- generator function support for transactions
- traverse,pick and omit methods for Model and QueryBuilder
- bugfix: issue #38
0.2.7
What's new
- bugfix: fix #37 also for
$query(). - Significant
toJson/fromJsonperformance boost.
0.2.6
What's new
- bugfix: fix regression bug that broke dumpSql.
0.2.5
What's new
- bugfix: fix regression bug that prevented values assigned to
thisin$beforecallbacks from getting into the actual database query
0.2.4
What's new
- bugfix: many-to-many relations didn't work correctly with a snake_case to camelCase conversion in the related model class.
0.2.3
What's new
- Promise constructor is now exposed through
require('objection').Promise.
0.2.2
What's new
- $beforeUpdate, $afterUpdate, $beforeInsert etc. are now asynchronous and you can return promises from them.
- Added
Model.fn()shortcut toknex.fn. - Added missing
asCallbackandnodeifymethods forQueryBuilder.
0.2.1
What's new
- bugfix: Chaining
insertwithreturningnow returns all listed columns.
0.2.0
What's new
- New name
objection.js. $beforeInsert,$afterInsert,$beforeUpdateand$afterUpdatehooks forModel.- Postgres jsonb query methods:
whereJsonEquals,whereJsonSupersetOf,whereJsonSubsetOfand friends. whereRefquery method.- Expose
knex.raw()throughModel.raw(). - Expose
knex.client.formatter()throughModel.formatter(). QueryBuildercan be used to make sub queries just like knex'sQueryBuilder.- Possibility to use a custom
QueryBuildersubclass by overridingModel.QueryBuilder. - Filter queries/objects for relations.
- A pile of bug fixes.
Breaking changes
- Project was renamed to objection.js. Migrate simply by replacing
moronwithobjection.
0.1.0
First release.