# Changelog

# 3.1.5

# What's new

# 3.1.4

# What's new

  • Fix upsertGraph() $beforeUpdate() calls on empty relates #2605 (opens new window)
  • Don't call onError() with internal exceptions #2603 (opens new window)
  • Remove docs and typings for nonexistent $pick()
  • Make $omitFromJson() + $omitFromDatabaseJson() compatible with old $omit() syntax

# 3.1.3

# What's new

# What's new

# 3.1.2

# What's new

# 3.1.1

# What's new

# 3.1.0

# What's new

# 3.0.5

# What's new

# 3.0.4

# What's new

# 3.0.3

# What's new

# 3.0.2

# What's new

# 3.0.1

# What's new

# 3.0.0

# What's new

# Breaking changes

See the migration guide.

# 2.2.10

# What's new

  • Add modelClass property for ValidationError and NotFoundError.

# 2.2.9

# What's new

  • Add noWait query builder method.

# 2.2.8

# What's new

# 2.2.7

# What's new

  • QueryBuilder.castTo can now be used to cast query results to any typescript type.

# 2.2.6

# What's new

# 2.2.5

# What's new

# 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

# 2.1.3

# What's new

# 2.1.2

# What's new

  • Fix startTransaction typings.

# 2.1.1

# What's new

# 2.1.0

# What's new

# Changelog

# 2.0.10

# What's new

# 2.0.9

# What's new

# 2.0.8

# What's new

# 2.0.7

# What's new

# 2.0.6

# What's new

# 2.0.5

# What's new

# 2.0.4

# What's new

  • New skipFetched option for fetchGraph and $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 -> withGraphFetched
    • joinEager -> withGraphJoined
    • removed eagerAlgorithm (you must explicitly use either withGraphFetched or withGraphJoined)
    • merged allowEager, allowInsert and allowUpsert into one method allowGraph
    • $loadRelated -> $fetchGraph
    • joinRelation -> joinRelated
    • $relatedQuery no longer mutates the receiving model instances
  • New static hook API. The old instance hooks are still around.

  • relatedQuery can 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 (opens new window) for more info.

  • Objection now uses the db-errors (opens new window) library by default to wrap the database errors.

  • insertMissing upsertGraph option now works as expected with relate: 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 bluebird and lodash.

  • In addition to all of this, a huge number of bugs has been squashed!

# Breaking changes

See the migration guide.

# 1.6.10

# 1.6.9

  • Revert fix for #1089 (opens new window). It was causing more bugs than it fixed. #1089 will be addressed in 2.0.
  • Typings updates

# 1.6.8

# 1.6.7

  • A bunch of regression bug fixes.

# 1.6.3

# 1.6.2

  • Add as method for raw making it possible to use raw expressions in joinEager modifiers (as long as you give names to your raw expressions using as).

# 1.6.1

  • Fix some very rare upsertGraph edge cases.

# 1.6.0

  • Add Model.traverseAsync and modelInstance.$traverseAsync methods.

  • Fixes: #842 (opens new window) and #1205 (opens new window). 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 from in 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 (opens new window)

  • Fixes: #1206 (opens new window)

# 1.5.3

# What's new

# 1.5.1

# What's new

  • Relations are now loaded lazily #1202 (opens new window)
  • relationMappings.modelClass can now be a function that returns a model class.

# 1.5.0

# What's new

# 1.4.0

# What's new

# 1.3.0

# What's new

# 1.2.3

# What's new

# 1.2.2

# What's new

  • Improve reference cycle detection in upsertGraph

# 1.2.1

# What's new

# 1.2.0

# What's new

# 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

# 1.1.8

# What's new

# 1.1.7

# What's new

# 1.1.6

# What's new

  • Add typings for fetchTableMetadata, tableMetadata and onbuildknex

# 1.1.5

# What's new

# 1.1.4

# What's new

  • fix subquery bug causing incompatibility with knex 0.14.5 and sqlite3

# 1.1.3

# What's new

# 1.1.2

# What's new

# 1.1.1

# What's new

# 1.1.0

# What's new

# 1.0.1

# What's new

# 1.0.0 🎉

# What's new

# Breaking changes

  • modelInstance.$query().delete().returning(something) now returns a single instance instead of an array. #659 (opens new window)

  • Node 6.0.0 is now the minimum. Objection will not work on node < 6.0.0.

  • ValidationError overhaul. This is a big one, so read this carefully! There are three things to check when you migrate to 1.0:

    1. The createValidationError and ValidationError interfaces have changed. If you have overridden the createValidationError method in your project, or you create custom ValidationError instances you need migrate to the interfaces.
    2. The model validation errors (jsonSchema violations) have remained pretty much the same but there are couple of differences. Before, the keys of error.data were property names even when a nested object in a graph failed a validation. Now the keys for nested validation errors are key paths like foo.bar[2].spam. Another tiny difference is the order of validation errors for each key in error.data. Let's say a property spam failed for your model and error.data.spam contains 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.
    3. All ValidationErrors now have a type field. Before all ValidationErrors but 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 in error.data. The error.data is now removed from those errors and the type should be used instead. The message from the data is now stored in error.message.
  • Removed deprecated methods whereRef, whereJsonField and whereJsonEquals. The ref helper can be used to replace the whereRef calls. ref and lit can be used to replace the removed json methods.

  • ManyToMany extras now work consistently in queries and filters. #760 (opens new window). 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 using Table.theColumn syntax.

# Changes

# 0.9.4

# What's new

# 0.9.3

# What's new

# 0.9.2

# What's new

  • Fix regression: from fails with a subquery.

# 0.9.1

# What's new

# 0.9.0

# What's new

# Breaking changes

# 0.8.8

# What's new

# 0.8.7

# What's new

# 0.8.6

# What's new

# 0.8.5

# What's new

# 0.8.4

# What's new

# 0.8.3

# What's new

# 0.8.2

# What's new

# 0.8.1

# What's new

# 0.8.0

# What's new

  • All query methods now call Model.query to create a QueryBuilder instance #346 (opens new window)
  • Objection is no longer transpiled. One of the implications is that you can use a github link in package.json to test experimental versions.
  • count can now be called without arguments #364 (opens new window)
  • A new getRelations method 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 class and extends keywords

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.extend method has also been removed. This means that you need to change your model definitions to use the class and extends keywords. To achieve this with the minimum amount of changes you can simply swap the constructor function and Model.extend to 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-classes anymore. See the ESNext example project (opens new window) as an example of how to setup babel.

  • The default value of pickJsonSchemaProperties was changed to false. Before, all properties that were not listed in jsonSchema were removed before insert, patch or update (if jsonSchma was defined). Starting from this version you need to explicitly set the value to true. You may have been used this feature by accident. If you have weird problems after the update, try setting objection.Model.pickJsonSchemaProperties = true; to see if it helps.

  • relate and unrelate methods now return the result of the underlying query (patch in case of HasManyRelation, HasOneRelation, and BelongsToOneRelation. insert otherwise). Before the method input was always returned.

  • Model.RelatedQueryBuilder is removed. Model.QueryBuilder is 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

# 0.7.11

# What's new

# 0.7.10

# What's new

  • fix bugs that prevented using $relatedQuery and eager together with JoinEagerAlgorithm
  • typing updates

# 0.7.9

# What's new

# 0.7.6

# What's new

# 0.7.5

# What's new

# 0.7.4

# What's new

# 0.7.3

# What's new

# 0.7.2

# What's new

  • HasOneThroughRelation relation type.

# 0.7.1

# What's new

  • fix JoinEagerAlgorithm NPE bug

# 0.7.0

# What's new

# Breaking changes

  • $relatedQuery now returns a single model instead of an array for belongsToOne and hasOne relations. #155 (opens new window)
  • identifier of a model can now be updated. Be careful with this one! Before if you forgot a wrong id in an update/patch operation, it would simply get ignored. Now the id is also updated just like any other column #100 (opens new window)
  • 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. #161 (opens new window)
  • ValidationError.data is now an object including, for each key, a list of errors with context info. #283 (opens new window)

# 0.6.2

# What's new

# 0.6.1

# What's new

# 0.6.0

# What's new

# 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 (opens new window) method can be called for a query builder to handle the undefined values the old way.

  • Deprecated method dumpSql is now removed.

  • $loadRelated and loadRelated now return a QueryBuilder. This may break your code is some rare cases where you have called a non-standard promise method like reflect for the return value of these functions.

# 0.5.5

# What's new

# 0.5.4

# What's new

  • bugfix: insertWithRelated now works with additionalProperties = false in jsonSchema
  • 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

# 0.5.0

# What's new

  • joinRelation family of query builder methods.
  • HasOneRelation for 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

# 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 ManyToMany relations in relationMappings. This is optional, but may be needed if you already have a model for a ManyToMany relation and you use snake_case to camelCase conversion 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 to where methods.
  • Added multiple missing knex methods to QueryBuilder.

# 0.3.0

# What's new

# Breaking changes

  • QueryBuilder methods update, patch and delete now return the number of affected rows. The new methods updateAndFetchById and patchAndFetchById may help with the migration
  • modelInstance.$query() instance method now returns a single model instead of an array
  • Removed Model.generateId() method. $beforeInsert can 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/fromJson performance 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 this in $before callbacks 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 to knex.fn.
  • Added missing asCallback and nodeify methods for QueryBuilder.

# 0.2.1

# What's new

  • bugfix: Chaining insert with returning now returns all listed columns.

# 0.2.0

# What's new

  • New name objection.js.
  • $beforeInsert, $afterInsert, $beforeUpdate and $afterUpdate hooks for Model.
  • Postgres jsonb query methods: whereJsonEquals, whereJsonSupersetOf, whereJsonSubsetOf and friends.
  • whereRef query method.
  • Expose knex.raw() through Model.raw().
  • Expose knex.client.formatter() through Model.formatter().
  • QueryBuilder can be used to make sub queries just like knex's QueryBuilder.
  • Possibility to use a custom QueryBuilder subclass by overriding Model.QueryBuilder.
  • Filter queries/objects for relations.
  • A pile of bug fixes.

# Breaking changes

  • Project was renamed to objection.js. Migrate simply by replacing moron with objection.

# 0.1.0

First release.