From f328630735f5cc93893309061b0a8431054cd61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 11:36:58 +0300 Subject: [PATCH 01/30] fixes #1455 --- doc/changelog/README.md | 4 + lib/queryBuilder/QueryBuilder.js | 4 +- lib/queryBuilder/graph/GraphUpsert.js | 26 ++- .../parsers/relationExpressionParser.js | 4 +- lib/relations/Relation.js | 8 +- lib/utils/assert.js | 4 +- package.json | 18 +- tests/integration/misc/#1455.js | 166 ++++++++++++++++++ tests/unit/relations/ManyToManyRelation.js | 12 +- typings/objection/index.d.ts | 4 +- 10 files changed, 217 insertions(+), 33 deletions(-) create mode 100644 tests/integration/misc/#1455.js diff --git a/doc/changelog/README.md b/doc/changelog/README.md index f72eca1a0..f70338714 100644 --- a/doc/changelog/README.md +++ b/doc/changelog/README.md @@ -1,5 +1,9 @@ # Changelog +## 1.6.10 + + * Fixes [#1455](https://github.com/Vincit/objection.js/issues/1455) + ## 1.6.9 * Revert fix for [#1089](https://github.com/Vincit/objection.js/issues/1089). It was causing more bugs than it fixed. #1089 will be addressed in 2.0. diff --git a/lib/queryBuilder/QueryBuilder.js b/lib/queryBuilder/QueryBuilder.js index c20834d72..7a6281ec7 100644 --- a/lib/queryBuilder/QueryBuilder.js +++ b/lib/queryBuilder/QueryBuilder.js @@ -1190,9 +1190,7 @@ function parseRelationExpression(modelClass, exp) { if (err instanceof DuplicateRelationError) { throw modelClass.createValidationError({ type: ValidationErrorType.RelationExpression, - message: `Duplicate relation name "${ - err.relationName - }" in relation expression "${exp}". Use "a.[b, c]" instead of "[a.b, a.c]".` + message: `Duplicate relation name "${err.relationName}" in relation expression "${exp}". Use "a.[b, c]" instead of "[a.b, a.c]".` }); } else { throw modelClass.createValidationError({ diff --git a/lib/queryBuilder/graph/GraphUpsert.js b/lib/queryBuilder/graph/GraphUpsert.js index 7a2a9a84d..143b66c06 100644 --- a/lib/queryBuilder/graph/GraphUpsert.js +++ b/lib/queryBuilder/graph/GraphUpsert.js @@ -93,8 +93,28 @@ function pruneRelatedBranches(graph, currentGraph, graphOptions) { function pruneDeletedBranches(graph, currentGraph) { const deleteNodes = currentGraph.nodes.filter(currentNode => !graph.nodeForNode(currentNode)); + const roots = findRoots(deleteNodes); + + // Don't delete relations the current graph doesn't even mention. + // So if the parent node doesn't even have the relation, it's not + // supposed to be deleted. + const rootsNotInRelation = roots.filter(deleteRoot => { + if (!deleteRoot.parentNode) { + return false; + } + + const { relation } = deleteRoot.parentEdge; + const parentNode = graph.nodeForNode(deleteRoot.parentNode); + + if (!parentNode) { + return false; + } - removeBranchesFromGraph(findRoots(deleteNodes), currentGraph); + return parentNode.obj[relation.name] === undefined; + }); + + removeBranchesFromGraph(roots, currentGraph); + removeNodesFromGraph(new Set(rootsNotInRelation), currentGraph); } function findRoots(nodes) { @@ -125,6 +145,10 @@ function removeBranchesFromGraph(branchRoots, graph) { ) ); + removeNodesFromGraph(nodesToRemove, graph); +} + +function removeNodesFromGraph(nodesToRemove, graph) { const edgesToRemove = new Set(); for (const node of nodesToRemove) { diff --git a/lib/queryBuilder/parsers/relationExpressionParser.js b/lib/queryBuilder/parsers/relationExpressionParser.js index de561e703..4c09e01e1 100644 --- a/lib/queryBuilder/parsers/relationExpressionParser.js +++ b/lib/queryBuilder/parsers/relationExpressionParser.js @@ -999,9 +999,7 @@ function peg$parse(input, options) { function assertDuplicateRelation(node, expr) { if (expr.$name in node) { console.warn( - `Duplicate relation "${ - expr.$name - }" in a relation expression. You should use "a.[b, c]" instead of "[a.b, a.c]". This will cause an error in objection 2.0` + `Duplicate relation "${expr.$name}" in a relation expression. You should use "a.[b, c]" instead of "[a.b, a.c]". This will cause an error in objection 2.0` ); // TODO: enable for v2.0. diff --git a/lib/relations/Relation.js b/lib/relations/Relation.js index 282590844..faca1da56 100644 --- a/lib/relations/Relation.js +++ b/lib/relations/Relation.js @@ -337,9 +337,7 @@ function createJoinProperties(ctx) { if (ownerProp.props.some(it => it === ctx.name)) { throw ctx.createError( - `join: relation name and join property '${ - ctx.name - }' cannot have the same name. If you cannot change one or the other, you can use $parseDatabaseJson and $formatDatabaseJson methods to convert the column name.` + `join: relation name and join property '${ctx.name}' cannot have the same name. If you cannot change one or the other, you can use $parseDatabaseJson and $formatDatabaseJson methods to convert the column name.` ); } @@ -358,9 +356,7 @@ function createRelationProperty(ctx, refString, propName) { } catch (err) { if (err instanceof RelationProperty.ModelNotFoundError) { throw ctx.createError( - `join: either \`from\` or \`to\` must point to the owner model table and the other one to the related table. It might be that specified table '${ - err.tableName - }' is not correct` + `join: either \`from\` or \`to\` must point to the owner model table and the other one to the related table. It might be that specified table '${err.tableName}' is not correct` ); } else if (err instanceof RelationProperty.InvalidReferenceError) { throw ctx.createError( diff --git a/lib/utils/assert.js b/lib/utils/assert.js index 09701ce9b..72a73d659 100644 --- a/lib/utils/assert.js +++ b/lib/utils/assert.js @@ -6,9 +6,7 @@ function assertHasId(model) { const ids = modelClass.getIdColumnArray().join(', '); throw new Error( - `one of the identifier columns [${ids}] is null or undefined. Have you specified the correct identifier column for the model '${ - modelClass.name - }' using the 'idColumn' property?` + `one of the identifier columns [${ids}] is null or undefined. Have you specified the correct identifier column for the model '${modelClass.name}' using the 'idColumn' property?` ); } } diff --git a/package.json b/package.json index 82eb5410c..31a7730e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "objection", - "version": "1.6.9", + "version": "1.6.10", "description": "An SQL-friendly ORM for Node.js", "main": "lib/objection.js", "license": "MIT", @@ -70,26 +70,26 @@ }, "devDependencies": { "@babel/polyfill": "^7.4.4", - "@types/node": "^10.14.7", + "@types/node": "^12.7.5", "babel-eslint": "^10.0.1", "chai": "^4.2.0", "chai-subset": "^1.6.0", "coveralls": "^3.0.3", - "cross-env": "^5.2.0", - "eslint": "^5.16.0", + "cross-env": "^6.0.0", + "eslint": "^6.4.0", "eslint-plugin-prettier": "^3.1.0", "expect.js": "^0.3.1", - "fs-extra": "^7.0.1", + "fs-extra": "^8.1.0", "glob": "^7.1.3", - "knex": "0.17.0", - "mocha": "^5.2.0", + "knex": "0.19.4", + "mocha": "^6.2.0", "mysql": "^2.17.1", "nyc": "^14.1.1", "pg": "^7.11.0", - "prettier": "1.17.1", + "prettier": "1.18.2", "sqlite3": "^4.0.8", "typescript": "^3.4.5", - "vuepress": "0.14.11" + "vuepress": "1.1.0" }, "nyc": { "description": "test coverage", diff --git a/tests/integration/misc/#1455.js b/tests/integration/misc/#1455.js new file mode 100644 index 000000000..03befa975 --- /dev/null +++ b/tests/integration/misc/#1455.js @@ -0,0 +1,166 @@ +const { Model, transaction } = require('../../../'); +const { expect } = require('chai'); + +module.exports = session => { + describe('UpsertGraph deletes rows for relation which is not mentioned in graph #1455', () => { + let knex = session.knex; + let Role; + + beforeEach(() => { + const { knex } = session; + + return knex.schema + .dropTableIfExists('roles') + .then(() => knex.schema.dropTableIfExists('sets')) + .then(() => knex.schema.dropTableIfExists('setsAttributes')) + .then(() => { + return knex.schema.createTable('roles', table => { + table.increments(); + table.string('name').notNullable(); + }); + }) + .then(() => { + return knex.schema.createTable('sets', table => { + table.increments(); + table.string('name').notNullable(); + table + .integer('roleId') + .unsigned() + .notNullable(); + }); + }) + .then(() => { + return knex.schema.createTable('setsAttributes', table => { + table.increments(); + table.string('name').notNullable(); + table + .integer('setId') + .unsigned() + .notNullable(); + }); + }); + }); + + afterEach(() => { + return knex.schema + .dropTableIfExists('roles') + .then(() => knex.schema.dropTableIfExists('sets')) + .then(() => knex.schema.dropTableIfExists('setsAttributes')); + }); + + beforeEach(() => { + const { knex } = session; + + class BaseModel extends Model { + static get useLimitInFirst() { + return true; + } + } + + class SetAttribute extends BaseModel { + static get tableName() { + return 'setsAttributes'; + } + } + + class Set extends BaseModel { + static get tableName() { + return 'sets'; + } + + static get relationMappings() { + return { + setAttributes: { + relation: BaseModel.HasManyRelation, + modelClass: SetAttribute, + join: { from: 'sets.id', to: 'setsAttributes.setId' } + } + }; + } + } + + Role = class Role extends BaseModel { + static get tableName() { + return 'roles'; + } + + static get relationMappings() { + return { + sets: { + relation: BaseModel.HasManyRelation, + modelClass: Set, + join: { from: 'roles.id', to: 'sets.roleId' } + } + }; + } + }; + + BaseModel.knex(knex); + }); + + it('test', () => { + return transaction(Role.knex(), trx => + Role.query(trx).insertGraph({ + name: 'First Role', + sets: [ + { + name: 'First Set', + setAttributes: [{ name: 'First SetAttribute' }, { name: 'Second SetAttribute' }] + } + ] + }) + ) + .then(role => { + return transaction(Role.knex(), trx => + Role.query(trx).upsertGraph({ + id: role.id, + sets: [ + { id: role.sets[0].id }, + { + name: 'Second Set', + setAttributes: [{ name: 'First SetAttribute' }, { name: 'Second SetAttribute' }] + } + ] + }) + ); + }) + .then(() => { + return Role.query() + .first() + .eager('sets(orderById).setAttributes(orderById)', { + orderById(query) { + query.orderBy('id'); + } + }); + }) + .then(setsAfterUpsertGraph => { + expect(setsAfterUpsertGraph).to.eql({ + id: 1, + name: 'First Role', + sets: [ + { + id: 1, + name: 'First Set', + roleId: 1, + + setAttributes: [ + { id: 1, name: 'First SetAttribute', setId: 1 }, + { id: 2, name: 'Second SetAttribute', setId: 1 } + ] + }, + { + id: 2, + name: 'Second Set', + roleId: 1, + + setAttributes: [ + { id: 3, name: 'First SetAttribute', setId: 2 }, + { id: 4, name: 'Second SetAttribute', setId: 2 } + ] + } + ] + }); + }); + }); + }); +}; diff --git a/tests/unit/relations/ManyToManyRelation.js b/tests/unit/relations/ManyToManyRelation.js index f5b9bb1be..6f242c33f 100644 --- a/tests/unit/relations/ManyToManyRelation.js +++ b/tests/unit/relations/ManyToManyRelation.js @@ -252,7 +252,7 @@ describe('ManyToManyRelation', () => { } }); }).to.throwException(err => { - expect(err.message).to.equal( + expect(err.message).to.contain( "OwnerModel.relationMappings.testRelation: Cannot find module '/not/a/path/to/a/model'" ); }); @@ -274,7 +274,7 @@ describe('ManyToManyRelation', () => { } }); }).to.throwException(err => { - expect(err.message).to.equal( + expect(err.message).to.contain( 'OwnerModel.relationMappings.testRelation: join.through must be an object that describes the join table. For example: {from: "JoinTable.someId", to: "JoinTable.someOtherId"}' ); }); @@ -296,7 +296,7 @@ describe('ManyToManyRelation', () => { } }); }).to.throwException(err => { - expect(err.message).to.equal( + expect(err.message).to.contain( 'OwnerModel.relationMappings.testRelation: join.through must be an object that describes the join table. For example: {from: "JoinTable.someId", to: "JoinTable.someOtherId"}' ); }); @@ -319,7 +319,7 @@ describe('ManyToManyRelation', () => { } }); }).to.throwException(err => { - expect(err.message).to.equal( + expect(err.message).to.contain( 'OwnerModel.relationMappings.testRelation: join.through.from must have format JoinTable.columnName. For example "JoinTable.someId" or in case of composite key ["JoinTable.a", "JoinTable.b"].' ); }); @@ -342,7 +342,7 @@ describe('ManyToManyRelation', () => { } }); }).to.throwException(err => { - expect(err.message).to.equal( + expect(err.message).to.contain( 'OwnerModel.relationMappings.testRelation: join.through.to must have format JoinTable.columnName. For example "JoinTable.someId" or in case of composite key ["JoinTable.a", "JoinTable.b"].' ); }); @@ -365,7 +365,7 @@ describe('ManyToManyRelation', () => { } }); }).to.throwException(err => { - expect(err.message).to.equal( + expect(err.message).to.contain( 'OwnerModel.relationMappings.testRelation: join.through `from` and `to` must point to the same join table.' ); }); diff --git a/typings/objection/index.d.ts b/typings/objection/index.d.ts index 3038d7165..0d8ee1243 100644 --- a/typings/objection/index.d.ts +++ b/typings/objection/index.d.ts @@ -722,7 +722,7 @@ declare namespace Objection { } type PartialUpdate = { - [P in keyof QM]?: QM[P] | Raw | Reference | QueryBuilder + [P in keyof QM]?: QM[P] | Raw | Reference | QueryBuilder; }; interface QueryBuilderBase extends QueryInterface { @@ -1556,7 +1556,7 @@ declare namespace Objection { */ type?: string | string[]; /** - * fallback raw string for custom formats, + * fallback raw string for custom formats, * or formats that aren't in the standard yet */ format?: JsonSchemaFormatType | string; From 6bfd731303dda9f90fde190736e1b1e527e9661e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 11:40:07 +0300 Subject: [PATCH 02/30] add node 12 to travis config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b43c2030d..07353e6f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ node_js: - '9' - '10' - '11' + - '12' before_script: - psql -U postgres -c "CREATE USER objection SUPERUSER" From 7ce258f7ae4a1af61bb7244686617908e13a059d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 11:43:20 +0300 Subject: [PATCH 03/30] dropping eslint back to 5.16.0 because 6 doesn't suppoort node 6 or 7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 31a7730e4..b99cd7aea 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "chai-subset": "^1.6.0", "coveralls": "^3.0.3", "cross-env": "^6.0.0", - "eslint": "^6.4.0", + "eslint": "^5.16.0", "eslint-plugin-prettier": "^3.1.0", "expect.js": "^0.3.1", "fs-extra": "^8.1.0", From 05d563b32230a013e046b40320af186d11d33565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 11:54:41 +0300 Subject: [PATCH 04/30] drop knex dev dep back to 0.17.x to support node 6 and 7 --- package.json | 2 +- tests/integration/misc/#1455.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b99cd7aea..618f1c96b 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "expect.js": "^0.3.1", "fs-extra": "^8.1.0", "glob": "^7.1.3", - "knex": "0.19.4", + "knex": "^0.17.0", "mocha": "^6.2.0", "mysql": "^2.17.1", "nyc": "^14.1.1", diff --git a/tests/integration/misc/#1455.js b/tests/integration/misc/#1455.js index 03befa975..eee8fae26 100644 --- a/tests/integration/misc/#1455.js +++ b/tests/integration/misc/#1455.js @@ -1,5 +1,5 @@ const { Model, transaction } = require('../../../'); -const { expect } = require('chai'); +const expect = require('expect.js'); module.exports = session => { describe('UpsertGraph deletes rows for relation which is not mentioned in graph #1455', () => { From da91a248960a34798ff994e7309288304493817f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 12:21:25 +0300 Subject: [PATCH 05/30] fixes #1471 --- lib/queryBuilder/QueryBuilder.js | 2 +- tests/integration/find.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/queryBuilder/QueryBuilder.js b/lib/queryBuilder/QueryBuilder.js index 7a6281ec7..4cf077b87 100644 --- a/lib/queryBuilder/QueryBuilder.js +++ b/lib/queryBuilder/QueryBuilder.js @@ -982,7 +982,7 @@ class QueryBuilder extends QueryBuilderBase { } range(...args) { - return this.addOperation(new RangeOperation('range'), args); + return this.clear(RangeOperation).addOperation(new RangeOperation('range'), args); } first(...args) { diff --git a/tests/integration/find.js b/tests/integration/find.js index 81450fde8..edafd5ef0 100644 --- a/tests/integration/find.js +++ b/tests/integration/find.js @@ -102,6 +102,18 @@ module.exports = session => { }); }); + it('calling page twice should override the previous call', () => { + return Model2.query() + .page(1, 2) + .page(0, 2) + .orderBy('model2_prop2', 'desc') + .then(result => { + expect(result.results[0]).to.be.a(Model2); + expect(result.total === 3).to.equal(true); + expect(_.map(result.results, 'model2Prop2')).to.eql([30, 20]); + }); + }); + describe('query builder methods', () => { it('.select()', () => { return Model2.query() From 8a5db6e1bc1843638a6f465c095fcddf0221bc74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 12:23:38 +0300 Subject: [PATCH 06/30] fixes #1470 --- typings/objection/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/objection/index.d.ts b/typings/objection/index.d.ts index 0d8ee1243..4e07e790e 100644 --- a/typings/objection/index.d.ts +++ b/typings/objection/index.d.ts @@ -347,7 +347,7 @@ declare namespace Objection { } interface JoinRelation { - (relationName: string, opt?: RelationOptions): QueryBuilder; + (expr: RelationExpression, opt?: RelationOptions): QueryBuilder; } type JsonObjectOrFieldExpression = object | object[] | FieldExpression; From 54da29195b0de689bfc51dd8e3711ffd91ea542e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 12:53:15 +0300 Subject: [PATCH 07/30] fixes #1364 --- lib/queryBuilder/QueryBuilder.js | 8 ++++- .../operations/UpdateAndFetchOperation.js | 15 +++++--- tests/integration/patch.js | 34 ++++++++++++++++++- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/lib/queryBuilder/QueryBuilder.js b/lib/queryBuilder/QueryBuilder.js index 4cf077b87..99718dd17 100644 --- a/lib/queryBuilder/QueryBuilder.js +++ b/lib/queryBuilder/QueryBuilder.js @@ -442,7 +442,7 @@ class QueryBuilder extends QueryBuilderBase { } clone() { - const builder = new this.constructor(this.modelClass()); + const builder = this.emptyInstance(); // Call the super class's clone implementation. this.baseCloneInto(builder); @@ -455,6 +455,12 @@ class QueryBuilder extends QueryBuilderBase { builder._allowedUpsertExpression = this._allowedUpsertExpression; builder._findOperationOptions = this._findOperationOptions; + return builder; + } + + emptyInstance() { + const builder = new this.constructor(this.modelClass()); + builder._findOperationFactory = this._findOperationFactory; builder._insertOperationFactory = this._insertOperationFactory; builder._updateOperationFactory = this._updateOperationFactory; diff --git a/lib/queryBuilder/operations/UpdateAndFetchOperation.js b/lib/queryBuilder/operations/UpdateAndFetchOperation.js index fa398a494..6d0eb9d6c 100644 --- a/lib/queryBuilder/operations/UpdateAndFetchOperation.js +++ b/lib/queryBuilder/operations/UpdateAndFetchOperation.js @@ -26,11 +26,11 @@ class UpdateAndFetchOperation extends DelegateOperation { } onBuild(builder) { - super.onBuild(builder); - if (!this.skipIdWhere) { builder.findById(this.id); } + + super.onBuild(builder); } onAfter2(builder, numUpdated) { @@ -39,11 +39,16 @@ class UpdateAndFetchOperation extends DelegateOperation { return afterReturn(super.onAfter2(builder, numUpdated), undefined); } + // Clone `this` query builder so that we get the correct + // operation factories in case of `$relatedQuery` etc. return builder - .modelClass() - .query() + .emptyInstance() .childQueryOf(builder) - .findById(this.id) + .modify(builder => { + if (!this.skipIdWhere) { + builder.findById(this.id); + } + }) .castTo(builder.resultModelClass()) .then(fetched => { let retVal = undefined; diff --git a/tests/integration/patch.js b/tests/integration/patch.js index 479c6ff64..369e33fcb 100644 --- a/tests/integration/patch.js +++ b/tests/integration/patch.js @@ -845,7 +845,6 @@ module.exports = session => { describe('has many relation', () => { let parent1; - let parent2; beforeEach(() => { return session.populate([ @@ -1123,6 +1122,39 @@ module.exports = session => { }); }); + it('should patch a related object with extras using patchAndFetchById', () => { + return Model1.query() + .findById(1) + .then(parent => { + return parent + .$relatedQuery('model1Relation3') + .debug() + .patchAndFetchById(4, { + model2Prop1: 'iam updated', + extra1: 'updated extra 1', + // Test query properties. sqlite doesn't have `concat` function. Use a literal for it. + extra2: isSqlite(session.knex) + ? 'updated extra 2' + : raw(`CONCAT('updated extra ', '2')`) + }); + }) + .then(result => { + chai.expect(result).to.containSubset({ + model2Prop1: 'iam updated', + extra1: 'updated extra 1', + extra2: 'updated extra 2', + idCol: 4 + }); + + return Model1.query() + .findById(1) + .eager('model1Relation3'); + }) + .then(model1 => { + console.dir(model1, { depth: null }); + }); + }); + it('should patch a related object with extras', () => { return Model1.query() .findById(1) From ddce93b33c3a936ed16d3ba846b5079e8b85223d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 13:29:44 +0300 Subject: [PATCH 08/30] fixes #1458 --- lib/model/Model.js | 8 +++++++ .../QueryBuilderOperationSupport.js | 7 +++--- .../operations/QueryBuilderOperation.js | 8 +++++++ lib/relations/Relation.js | 14 +++++++---- lib/transaction.js | 12 ++++++---- lib/utils/classUtils.js | 19 --------------- lib/utils/resolveModel.js | 21 ++++++++-------- tests/unit/relations/ManyToManyRelation.js | 24 +++++++++++++++---- tests/unit/utils.js | 20 ---------------- 9 files changed, 67 insertions(+), 66 deletions(-) diff --git a/lib/model/Model.js b/lib/model/Model.js index 86a47935e..7027e1fe5 100644 --- a/lib/model/Model.js +++ b/lib/model/Model.js @@ -725,6 +725,14 @@ class Model { } } +Object.defineProperties(Model, { + isObjectionModelClass: { + enumerable: false, + writable: false, + value: true + } +}); + Object.defineProperties(Model.prototype, { $isObjectionModel: { enumerable: false, diff --git a/lib/queryBuilder/QueryBuilderOperationSupport.js b/lib/queryBuilder/QueryBuilderOperationSupport.js index 760f3a5d6..793599bfe 100644 --- a/lib/queryBuilder/QueryBuilderOperationSupport.js +++ b/lib/queryBuilder/QueryBuilderOperationSupport.js @@ -2,9 +2,7 @@ const promiseUtils = require('../utils/promiseUtils'); -const { isSubclassOf } = require('../utils/classUtils'); const { isString, isFunction, isRegExp, last } = require('../utils/objectUtils'); -const { QueryBuilderOperation } = require('./operations/QueryBuilderOperation'); const { QueryBuilderContextBase } = require('./QueryBuilderContextBase'); const { QueryBuilderUserContext } = require('./QueryBuilderUserContext'); @@ -468,7 +466,10 @@ function buildFunctionForOperationSelector(operationSelector) { return op => operationSelector.test(op.name); } else if (isString(operationSelector)) { return op => op.name === operationSelector; - } else if (isSubclassOf(operationSelector, QueryBuilderOperation)) { + } else if ( + isFunction(operationSelector) && + operationSelector.isObjectionQueryBuilderOperationClass + ) { return op => op.is(operationSelector); } else if (isFunction(operationSelector)) { return operationSelector; diff --git a/lib/queryBuilder/operations/QueryBuilderOperation.js b/lib/queryBuilder/operations/QueryBuilderOperation.js index e5655f983..ed3f06c38 100644 --- a/lib/queryBuilder/operations/QueryBuilderOperation.js +++ b/lib/queryBuilder/operations/QueryBuilderOperation.js @@ -252,6 +252,14 @@ class QueryBuilderOperation { } } +Object.defineProperties(QueryBuilderOperation, { + isObjectionQueryBuilderOperationClass: { + enumerable: false, + writable: false, + value: true + } +}); + module.exports = { QueryBuilderOperation }; diff --git a/lib/relations/Relation.js b/lib/relations/Relation.js index faca1da56..609a7fb9c 100644 --- a/lib/relations/Relation.js +++ b/lib/relations/Relation.js @@ -1,7 +1,6 @@ 'use strict'; const { RelationProperty } = require('./RelationProperty'); -const getModel = () => require('../model/Model').Model; const { RelationFindOperation } = require('./RelationFindOperation'); const { RelationUpdateOperation } = require('./RelationUpdateOperation'); @@ -9,7 +8,6 @@ const { RelationDeleteOperation } = require('./RelationDeleteOperation'); const { RelationSubqueryOperation } = require('./RelationSubqueryOperation'); const { ref } = require('../queryBuilder/ReferenceBuilder'); -const { isSubclassOf } = require('../utils/classUtils'); const { resolveModel } = require('../utils/resolveModel'); const { get, isFunction } = require('../utils/objectUtils'); const { mapAfterAllReturn } = require('../utils/promiseUtils'); @@ -248,6 +246,14 @@ class Relation { } } +Object.defineProperties(Relation, { + isObjectionRelationClass: { + enumerable: false, + writable: false, + value: true + } +}); + Object.defineProperties(Relation.prototype, { isObjectionRelation: { enumerable: false, @@ -267,7 +273,7 @@ function checkForbiddenProperties(ctx) { } function checkOwnerModelClass(ctx) { - if (!isSubclassOf(ctx.ownerModelClass, getModel())) { + if (!isFunction(ctx.ownerModelClass) || !ctx.ownerModelClass.isObjectionModelClass) { throw ctx.createError(`Relation's owner is not a subclass of Model`); } @@ -303,7 +309,7 @@ function checkRelation(ctx) { throw ctx.createError('relation is not defined'); } - if (!isSubclassOf(ctx.mapping.relation, Relation)) { + if (!isFunction(ctx.mapping.relation) || !ctx.mapping.relation.isObjectionRelationClass) { throw ctx.createError('relation is not a subclass of Relation'); } diff --git a/lib/transaction.js b/lib/transaction.js index ce5a35c4f..f6f7d74a0 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -1,9 +1,7 @@ 'use strict'; const Bluebird = require('bluebird'); -const { Model } = require('./model/Model'); const promiseUtils = require('./utils/promiseUtils'); -const { isSubclassOf } = require('./utils/classUtils'); const { isFunction } = require('./utils/objectUtils'); function transaction() { @@ -18,7 +16,7 @@ function transaction() { let args = Array.from(arguments); - if (!isSubclassOf(args[0], Model) && isFunction(args[0].transaction)) { + if (!isModelClass(args[0]) && isFunction(args[0].transaction)) { let knex = args[0]; args = args.slice(1); @@ -35,7 +33,7 @@ function transaction() { let i; for (i = 0; i < modelClasses.length; ++i) { - if (!isSubclassOf(modelClasses[i], Model)) { + if (!isModelClass(modelClasses[i])) { return Bluebird.reject( new Error('objection.transaction: all but the last argument should be Model subclasses') ); @@ -77,7 +75,7 @@ function transaction() { transaction.start = function(modelClassOrKnex) { let knex = modelClassOrKnex; - if (isSubclassOf(modelClassOrKnex, Model)) { + if (isModelClass(modelClassOrKnex)) { knex = modelClassOrKnex.knex(); } @@ -104,6 +102,10 @@ function isGenerator(fn) { return fn && fn.constructor && fn.constructor.name === 'GeneratorFunction'; } +function isModelClass(maybeModel) { + return isFunction(maybeModel) && maybeModel.isObjectionModelClass; +} + module.exports = { transaction }; diff --git a/lib/utils/classUtils.js b/lib/utils/classUtils.js index 03121c14b..2a38f8e8a 100644 --- a/lib/utils/classUtils.js +++ b/lib/utils/classUtils.js @@ -1,23 +1,5 @@ 'use strict'; -const { isFunction } = require('./objectUtils'); - -function isSubclassOf(Constructor, SuperConstructor) { - if (!isFunction(SuperConstructor)) { - return false; - } - - while (isFunction(Constructor)) { - if (Constructor === SuperConstructor) { - return true; - } - - Constructor = Object.getPrototypeOf(Constructor); - } - - return false; -} - function inherit(Constructor, BaseConstructor) { Constructor.prototype = Object.create(BaseConstructor.prototype); Constructor.prototype.constructor = BaseConstructor; @@ -27,6 +9,5 @@ function inherit(Constructor, BaseConstructor) { } module.exports = { - isSubclassOf, inherit }; diff --git a/lib/utils/resolveModel.js b/lib/utils/resolveModel.js index 324d6224e..753cb1845 100644 --- a/lib/utils/resolveModel.js +++ b/lib/utils/resolveModel.js @@ -1,10 +1,8 @@ 'use strict'; const path = require('path'); -const { once, isString, isFunction } = require('../utils/objectUtils'); -const { isSubclassOf } = require('../utils/classUtils'); +const { isString, isFunction } = require('../utils/objectUtils'); -const getModel = once(() => require('../model/Model').Model); class ResolveError extends Error {} function resolveModel(modelRef, modelPaths, errorPrefix) { @@ -16,11 +14,11 @@ function resolveModel(modelRef, modelPaths, errorPrefix) { return requireUsingModelPaths(modelRef, modelPaths); } } else { - if (isFunction(modelRef) && !isSubclassOf(modelRef, getModel())) { + if (isFunction(modelRef) && !isModelClass(modelRef)) { modelRef = modelRef(); } - if (!isSubclassOf(modelRef, getModel())) { + if (!isModelClass(modelRef)) { throw new ResolveError( `is not a subclass of Model or a file path to a module that exports one. You may be dealing with a require loop. See the documentation section about require loops.` ); @@ -58,7 +56,6 @@ function requireUsingModelPaths(modelRef, modelPaths) { } function requireModel(modelPath) { - const Model = getModel(); /** * Wrap path string in template literal to prevent * warnings about Objection.JS being an expression @@ -68,16 +65,16 @@ function requireModel(modelPath) { let mod = require(`${path.resolve(modelPath)}`); let modelClass = null; - if (isSubclassOf(mod, Model)) { + if (isModelClass(mod)) { modelClass = mod; - } else if (isSubclassOf(mod.default, Model)) { + } else if (isModelClass(mod.default)) { // Babel 6 style of exposing default export. modelClass = mod.default; } else { Object.keys(mod).forEach(exportName => { const exp = mod[exportName]; - if (isSubclassOf(exp, Model)) { + if (isModelClass(exp)) { if (modelClass !== null) { throw new ResolveError( `path ${modelPath} exports multiple models. Don't know which one to choose.` @@ -89,7 +86,7 @@ function requireModel(modelPath) { }); } - if (!isSubclassOf(modelClass, Model)) { + if (!isModelClass(modelClass)) { throw new ResolveError(`${modelPath} is an invalid file path to a model class`); } @@ -100,6 +97,10 @@ function isAbsolutePath(pth) { return path.normalize(pth + '/') === path.normalize(path.resolve(pth) + '/'); } +function isModelClass(maybeModel) { + return isFunction(maybeModel) && maybeModel.isObjectionModelClass; +} + module.exports = { resolveModel }; diff --git a/tests/unit/relations/ManyToManyRelation.js b/tests/unit/relations/ManyToManyRelation.js index 6f242c33f..60fe1b021 100644 --- a/tests/unit/relations/ManyToManyRelation.js +++ b/tests/unit/relations/ManyToManyRelation.js @@ -3,7 +3,7 @@ const Knex = require('knex'); const expect = require('expect.js'); const Promise = require('bluebird'); const objection = require('../../../'); -const classUtils = require('../../../lib/utils/classUtils'); +const { isFunction } = require('../../../lib/utils/objectUtils'); const knexMocker = require('../../../testUtils/mockKnex'); const Model = objection.Model; @@ -140,7 +140,7 @@ describe('ManyToManyRelation', () => { expect(relation.joinTable).to.equal('JoinModel'); expect(relation.joinTableOwnerProp.cols).to.eql(['ownerId']); expect(relation.joinTableRelatedProp.props).to.eql(['relatedId']); - expect(classUtils.isSubclassOf(relation.joinModelClass, JoinModel)).to.equal(true); + expect(isSubclassOf(relation.joinModelClass, JoinModel)).to.equal(true); }); it('should accept an absolute file path to a join model in join.through object', () => { @@ -163,9 +163,7 @@ describe('ManyToManyRelation', () => { expect(relation.joinTable).to.equal('JoinModel'); expect(relation.joinTableOwnerProp.cols).to.eql(['ownerId']); expect(relation.joinTableRelatedProp.cols).to.eql(['relatedId']); - expect(classUtils.isSubclassOf(relation.joinModelClass, require('./files/JoinModel'))).to.equal( - true - ); + expect(isSubclassOf(relation.joinModelClass, require('./files/JoinModel'))).to.equal(true); }); it('should accept a composite keys in join.through object (1)', () => { @@ -1480,3 +1478,19 @@ describe('ManyToManyRelation', () => { }); } }); + +function isSubclassOf(Constructor, SuperConstructor) { + if (!isFunction(SuperConstructor)) { + return false; + } + + while (isFunction(Constructor)) { + if (Constructor === SuperConstructor) { + return true; + } + + Constructor = Object.getPrototypeOf(Constructor); + } + + return false; +} diff --git a/tests/unit/utils.js b/tests/unit/utils.js index 13128e1ae..7a49eb515 100644 --- a/tests/unit/utils.js +++ b/tests/unit/utils.js @@ -15,26 +15,6 @@ const { map } = require('../../lib/utils/promiseUtils'); const { jsonEquals } = require('../../lib/utils/objectUtils'); describe('utils', () => { - describe('isSubclassOf', () => { - class A {} - class B extends A {} - class C extends B {} - - it('should return true for subclass constructor', () => { - expect(classUtils.isSubclassOf(B, A)).to.equal(true); - expect(classUtils.isSubclassOf(C, B)).to.equal(true); - expect(classUtils.isSubclassOf(C, A)).to.equal(true); - expect(classUtils.isSubclassOf(A, B)).to.equal(false); - expect(classUtils.isSubclassOf(B, C)).to.equal(false); - expect(classUtils.isSubclassOf(A, C)).to.equal(false); - }); - - it('should return false if one of the inputs is not a constructor', () => { - expect(classUtils.isSubclassOf(function() {}, {})).to.equal(false); - expect(classUtils.isSubclassOf({}, function() {})).to.equal(false); - }); - }); - describe('mixin', () => { it('should mixin rest of the arguments to the first argument', () => { class X {} From 000c59aa9111a7eb9d4179f83bf7a3c025fb34c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 14:15:22 +0300 Subject: [PATCH 09/30] fixes #1467 --- lib/relations/RelationProperty.js | 6 +- tests/integration/misc/#1467.js | 213 ++++++++++++++++++++++++++++++ tests/integration/patch.js | 20 ++- 3 files changed, 225 insertions(+), 14 deletions(-) create mode 100644 tests/integration/misc/#1467.js diff --git a/lib/relations/RelationProperty.js b/lib/relations/RelationProperty.js index ec5d914b2..6dbcd6169 100644 --- a/lib/relations/RelationProperty.js +++ b/lib/relations/RelationProperty.js @@ -42,7 +42,7 @@ class RelationProperty { this._cols = refs.map(it => it.column); this._propGetters = paths.map(it => createGetter(it.path)); this._propSetters = paths.map(it => createSetter(it.path)); - this._patchers = refs.map(it => createPatcher(it)); + this._patchers = refs.map((it, i) => createPatcher(it, paths[i].path)); } static get ModelNotFoundError() { @@ -227,9 +227,9 @@ function createSetter(path) { } } -function createPatcher(ref) { +function createPatcher(ref, path) { if (ref.isPlainColumnRef) { - return (patch, value) => (patch[ref.column] = value); + return (patch, value) => (patch[path[0]] = value); } else { // Objection `patch`, `update` etc. methods understand field expressions. return (patch, value) => (patch[ref.expression] = value); diff --git a/tests/integration/misc/#1467.js b/tests/integration/misc/#1467.js new file mode 100644 index 000000000..daa92d974 --- /dev/null +++ b/tests/integration/misc/#1467.js @@ -0,0 +1,213 @@ +const { Model, snakeCaseMappers } = require('../../../'); +const chai = require('chai'); + +module.exports = session => { + describe('Not CamelCasing ref.column #1467', () => { + let knex = session.knex; + let Campaign, Deliverable; + + beforeEach(() => { + const { knex } = session; + + return Promise.resolve() + .then(() => knex.schema.dropTableIfExists('cogs')) + .then(() => knex.schema.dropTableIfExists('campaigns')) + .then(() => knex.schema.dropTableIfExists('deliverables')) + .then(() => { + return knex.schema + .createTable('campaigns', table => { + table.increments('id').primary(); + }) + .createTable('deliverables', table => { + table.increments('id').primary(); + }) + .createTable('cogs', table => { + table.increments('id').primary(); + table + .integer('campaign_id') + .unsigned() + .references('id') + .inTable('campaigns'); + table + .integer('deliverable_id') + .unsigned() + .references('id') + .inTable('deliverables'); + }); + }); + }); + + afterEach(() => { + return Promise.resolve() + .then(() => knex.schema.dropTableIfExists('cogs')) + .then(() => knex.schema.dropTableIfExists('campaigns')) + .then(() => knex.schema.dropTableIfExists('deliverables')); + }); + + beforeEach(() => { + Campaign = class Campaign extends Model { + static get tableName() { + return 'campaigns'; + } + + static get columnNameMappers() { + return snakeCaseMappers(); + } + + static get jsonSchema() { + return { + type: 'object', + properties: { + id: { type: 'integer' } + }, + additionalProperties: false + }; + } + + static get relationMappings() { + return { + cogs: { + relation: Model.HasManyRelation, + modelClass: Cog, + join: { + from: 'campaigns.id', + to: 'cogs.campaign_id' + } + } + }; + } + }; + + class Cog extends Model { + static get tableName() { + return 'cogs'; + } + + static get columnNameMappers() { + return snakeCaseMappers(); + } + + static get jsonSchema() { + return { + type: 'object', + properties: { + id: { type: 'integer' }, + campaignId: { type: ['integer', 'null'] }, + deliverableId: { type: ['integer', 'null'] } + }, + additionalProperties: false + }; + } + + static get relationMappings() { + return {}; + } + } + + Deliverable = class Deliverable extends Model { + static get tableName() { + return 'deliverables'; + } + + static get columnNameMappers() { + return snakeCaseMappers(); + } + + static get jsonSchema() { + return { + type: 'object', + properties: { + id: { type: 'integer' } + }, + additionalProperties: false + }; + } + + static get relationMappings() { + return { + cogs: { + relation: Model.HasManyRelation, + modelClass: Cog, + join: { + from: 'deliverables.id', + to: 'cogs.deliverable_id' + } + } + }; + } + }; + + Campaign.knex(session.knex); + Deliverable.knex(session.knex); + }); + + it('test', () => { + return Promise.resolve() + .then(() => { + return Promise.all([ + Campaign.query().insertGraph({}), + Deliverable.query().insertGraph({}) + ]); + }) + .then(([campaign, deliverable]) => { + return Promise.resolve() + .then(() => { + return Campaign.query().upsertGraph( + { id: campaign.id, cogs: [{ deliverableId: deliverable.id }] }, + { relate: ['cogs'], unrelate: ['cogs'] } + ); + }) + .then(() => { + return Campaign.query() + .findOne({}) + .eager('cogs'); + }) + .then(c1 => { + chai.expect(c1.cogs.length).to.equal(1); + }) + .then(() => { + return Campaign.query().upsertGraph( + { id: campaign.id, cogs: [] }, + { relate: ['cogs'], unrelate: ['cogs'] } + ); + }) + .then(() => { + return Campaign.query() + .findOne({}) + .eager('cogs'); + }) + .then(c2 => { + chai.expect(c2.cogs.length).to.equal(0); + }) + .then(() => { + return Deliverable.query().upsertGraph( + { id: deliverable.id, cogs: [{ campaignId: campaign.id }] }, + { relate: ['cogs'], unrelate: ['cogs'] } + ); + }) + .then(() => { + return Deliverable.query() + .findOne({}) + .eager('cogs'); + }) + .then(d1 => { + chai.expect(d1.cogs.length).to.equal(1); + }) + .then(() => { + return Deliverable.query().upsertGraph( + { id: deliverable.id, cogs: [] }, + { relate: ['cogs'], unrelate: ['cogs'] } + ); + }) + .then(() => { + return Deliverable.query() + .findOne({}) + .eager('cogs'); + }) + .then(d2 => { + chai.expect(d2.cogs.length).to.equal(0); + }); + }); + }); + }); +}; diff --git a/tests/integration/patch.js b/tests/integration/patch.js index 369e33fcb..6071b6225 100644 --- a/tests/integration/patch.js +++ b/tests/integration/patch.js @@ -845,6 +845,7 @@ module.exports = session => { describe('has many relation', () => { let parent1; + let parent2; beforeEach(() => { return session.populate([ @@ -1126,17 +1127,14 @@ module.exports = session => { return Model1.query() .findById(1) .then(parent => { - return parent - .$relatedQuery('model1Relation3') - .debug() - .patchAndFetchById(4, { - model2Prop1: 'iam updated', - extra1: 'updated extra 1', - // Test query properties. sqlite doesn't have `concat` function. Use a literal for it. - extra2: isSqlite(session.knex) - ? 'updated extra 2' - : raw(`CONCAT('updated extra ', '2')`) - }); + return parent.$relatedQuery('model1Relation3').patchAndFetchById(4, { + model2Prop1: 'iam updated', + extra1: 'updated extra 1', + // Test query properties. sqlite doesn't have `concat` function. Use a literal for it. + extra2: isSqlite(session.knex) + ? 'updated extra 2' + : raw(`CONCAT('updated extra ', '2')`) + }); }) .then(result => { chai.expect(result).to.containSubset({ From 722c2c9c6c2ea7b84109003dc086574c474d205c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 14:25:47 +0300 Subject: [PATCH 10/30] v1.6.11 --- doc/changelog/README.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/changelog/README.md b/doc/changelog/README.md index f70338714..85f74efaf 100644 --- a/doc/changelog/README.md +++ b/doc/changelog/README.md @@ -1,5 +1,13 @@ # Changelog +## 1.6.11 + + * Fixes [#1471](https://github.com/Vincit/objection.js/issues/1471) + * Fixes [#1470](https://github.com/Vincit/objection.js/issues/1470) + * Fixes [#1364](https://github.com/Vincit/objection.js/issues/1364) + * Fixes [#1458](https://github.com/Vincit/objection.js/issues/1458) + * Fixes [#1467](https://github.com/Vincit/objection.js/issues/1467) + ## 1.6.10 * Fixes [#1455](https://github.com/Vincit/objection.js/issues/1455) diff --git a/package.json b/package.json index 618f1c96b..71261edce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "objection", - "version": "1.6.10", + "version": "1.6.11", "description": "An SQL-friendly ORM for Node.js", "main": "lib/objection.js", "license": "MIT", From 34152277e9ada82a81a9015d5b37e114ea5dc19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 15:00:01 +0300 Subject: [PATCH 11/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3e9db88c..81b6124fc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/Vincit/objection.js.svg?branch=master)](https://travis-ci.org/Vincit/objection.js) [![Coverage Status](https://coveralls.io/repos/github/Vincit/objection.js/badge.svg?branch=master&service=github)](https://coveralls.io/github/Vincit/objection.js?branch=master) [![Join the chat at https://gitter.im/Vincit/objection.js](https://badges.gitter.im/Vincit/objection.js.svg)](https://gitter.im/Vincit/objection.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/Vincit/objection.js.svg?branch=master)](https://travis-ci.org/Vincit/objection.js) [![Coverage Status](https://coveralls.io/repos/github/Vincit/objection.js/badge.svg?branch=master&service=github1)](https://coveralls.io/github/Vincit/objection.js?branch=master) [![Join the chat at https://gitter.im/Vincit/objection.js](https://badges.gitter.im/Vincit/objection.js.svg)](https://gitter.im/Vincit/objection.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) # [Objection.js](https://vincit.github.io/objection.js) From f6b369212966b790707d94cc630453b727fd08dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 15:00:26 +0300 Subject: [PATCH 12/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81b6124fc..d3e9db88c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/Vincit/objection.js.svg?branch=master)](https://travis-ci.org/Vincit/objection.js) [![Coverage Status](https://coveralls.io/repos/github/Vincit/objection.js/badge.svg?branch=master&service=github1)](https://coveralls.io/github/Vincit/objection.js?branch=master) [![Join the chat at https://gitter.im/Vincit/objection.js](https://badges.gitter.im/Vincit/objection.js.svg)](https://gitter.im/Vincit/objection.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/Vincit/objection.js.svg?branch=master)](https://travis-ci.org/Vincit/objection.js) [![Coverage Status](https://coveralls.io/repos/github/Vincit/objection.js/badge.svg?branch=master&service=github)](https://coveralls.io/github/Vincit/objection.js?branch=master) [![Join the chat at https://gitter.im/Vincit/objection.js](https://badges.gitter.im/Vincit/objection.js.svg)](https://gitter.im/Vincit/objection.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) # [Objection.js](https://vincit.github.io/objection.js) From 4ffa851d55c3232e5425c050772bc31fe23f4e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 15:01:14 +0300 Subject: [PATCH 13/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3e9db88c..c474987a6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/Vincit/objection.js.svg?branch=master)](https://travis-ci.org/Vincit/objection.js) [![Coverage Status](https://coveralls.io/repos/github/Vincit/objection.js/badge.svg?branch=master&service=github)](https://coveralls.io/github/Vincit/objection.js?branch=master) [![Join the chat at https://gitter.im/Vincit/objection.js](https://badges.gitter.im/Vincit/objection.js.svg)](https://gitter.im/Vincit/objection.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/Vincit/objection.js.svg?branch=master)](https://travis-ci.org/Vincit/objection.js) [![Coverage Status](https://coveralls.io/repos/github/Vincit/objection.js/badge.svg?branch=master&u=1)](https://coveralls.io/github/Vincit/objection.js?branch=master) [![Join the chat at https://gitter.im/Vincit/objection.js](https://badges.gitter.im/Vincit/objection.js.svg)](https://gitter.im/Vincit/objection.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) # [Objection.js](https://vincit.github.io/objection.js) From 59ec11e861dab4cce3114026d2a2526c8d898c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 14:41:46 +0300 Subject: [PATCH 14/30] fix unfinished test --- tests/integration/patch.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/integration/patch.js b/tests/integration/patch.js index 6071b6225..06d9e9124 100644 --- a/tests/integration/patch.js +++ b/tests/integration/patch.js @@ -1149,7 +1149,42 @@ module.exports = session => { .eager('model1Relation3'); }) .then(model1 => { - console.dir(model1, { depth: null }); + chai.expect(model1).to.containSubset({ + id: 1, + model1Id: null, + model1Prop1: 'hello 1', + model1Prop2: null, + model1Relation3: [ + { + idCol: 5, + model1Id: null, + model2Prop1: 'foo 3', + model2Prop2: null, + extra1: 'extra 13', + extra2: 'extra 23', + $afterGetCalled: 1 + }, + { + idCol: 4, + model1Id: null, + model2Prop1: 'iam updated', + model2Prop2: null, + extra1: 'updated extra 1', + extra2: 'updated extra 2', + $afterGetCalled: 1 + }, + { + idCol: 3, + model1Id: null, + model2Prop1: 'foo 1', + model2Prop2: null, + extra1: 'extra 11', + extra2: 'extra 21', + $afterGetCalled: 1 + } + ], + $afterGetCalled: 1 + }); }); }); From d9c6352231e881f0ba35d6a487c6f4f7d23b098c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 19:48:23 +0300 Subject: [PATCH 15/30] going back to vuepress 1.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 71261edce..9781e9653 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "prettier": "1.18.2", "sqlite3": "^4.0.8", "typescript": "^3.4.5", - "vuepress": "1.1.0" + "vuepress": "1.0.4" }, "nyc": { "description": "test coverage", From 5ab8ddd87286a3b04af51400e353cc270ecc6cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 21 Sep 2019 20:56:39 +0300 Subject: [PATCH 16/30] workaround vuepress bug https://github.com/vuejs/vuepress/issues/1802 --- .../theme/components/AlgoliaSearchBox.vue | 160 ++++++++++++++++++ doc/.vuepress/theme/index.js | 24 +++ 2 files changed, 184 insertions(+) create mode 100644 doc/.vuepress/theme/components/AlgoliaSearchBox.vue create mode 100644 doc/.vuepress/theme/index.js diff --git a/doc/.vuepress/theme/components/AlgoliaSearchBox.vue b/doc/.vuepress/theme/components/AlgoliaSearchBox.vue new file mode 100644 index 000000000..c2d443055 --- /dev/null +++ b/doc/.vuepress/theme/components/AlgoliaSearchBox.vue @@ -0,0 +1,160 @@ + + + + + diff --git a/doc/.vuepress/theme/index.js b/doc/.vuepress/theme/index.js new file mode 100644 index 000000000..c77d3dedf --- /dev/null +++ b/doc/.vuepress/theme/index.js @@ -0,0 +1,24 @@ +const path = require('path'); + +module.exports = (_, ctx) => ({ + // MODIFICATION_FROM_THEME - this alias method is imported without change + // to point to updated AlgoliaSearchBox.vue + alias() { + const { themeConfig, siteConfig } = ctx; + + // resolve algolia + const isAlgoliaSearch = + themeConfig.algolia || + Object.keys((siteConfig.locales && themeConfig.locales) || {}).some( + base => themeConfig.locales[base].algolia + ); + + return { + '@AlgoliaSearchBox': isAlgoliaSearch + ? path.resolve(__dirname, 'components/AlgoliaSearchBox.vue') + : path.resolve(__dirname, 'noopModule.js') + }; + }, + + extend: '@vuepress/theme-default' +}); From 119be282a214f7aad7723148b8fce96b74a89a17 Mon Sep 17 00:00:00 2001 From: Rodrigo Burdet Date: Thu, 26 Sep 2019 15:41:59 -0300 Subject: [PATCH 17/30] Fixing bug #1486 --- lib/queryBuilder/QueryBuilder.js | 15 ++++++++------ tests/unit/queryBuilder/QueryBuilder.js | 27 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/queryBuilder/QueryBuilder.js b/lib/queryBuilder/QueryBuilder.js index 99718dd17..ff6a2fd38 100644 --- a/lib/queryBuilder/QueryBuilder.js +++ b/lib/queryBuilder/QueryBuilder.js @@ -707,12 +707,15 @@ class QueryBuilder extends QueryBuilderBase { modelClass = null; } - // Turn the properties into a hash for performance. - properties = properties.reduce((obj, prop) => { - obj[prop] = true; - return obj; - }, {}); - + if (Array.isArray(properties)) { + // Turn the properties into a hash for performance. + properties = properties.reduce((obj, prop) => { + obj[prop] = true; + return obj; + }, {}); + } else { + properties = { [properties]: true }; + } return this.traverse(modelClass, model => { model.$omit(properties); }); diff --git a/tests/unit/queryBuilder/QueryBuilder.js b/tests/unit/queryBuilder/QueryBuilder.js index 7bba0aac8..1a895799b 100644 --- a/tests/unit/queryBuilder/QueryBuilder.js +++ b/tests/unit/queryBuilder/QueryBuilder.js @@ -2464,6 +2464,33 @@ describe('QueryBuilder', () => { }); }); }); + + describe('omit', () => { + it('omit properties from model when ommiting an array', done => { + mockKnexQueryResults = [[{ a: 1 }, { b: 2 }, { c: 3 }]]; + TestModel.query() + .omit(['a', 'b']) + .then(result => { + expect(result[0]).to.not.have.property('a'); + expect(result[1]).to.not.have.property('b'); + expect(result[2]).to.have.property('c'); + expect(result[2].c).to.be.equal(3); + done(); + }); + }); + + it('omit properties from model', done => { + mockKnexQueryResults = [[{ a: 1 }, { b: 2 }]]; + TestModel.query() + .omit('b') + .then(result => { + expect(result[0]).to.have.property('a'); + expect(result[0].a).to.be.equal(1); + expect(result[1]).to.not.have.property('b'); + done(); + }); + }); + }); }); const operationBuilder = QueryBuilder.forClass(Model); From 6e1fa8fe1b0d15db5db862259d78d75dae6b3ccc Mon Sep 17 00:00:00 2001 From: te1 Date: Thu, 3 Oct 2019 23:21:36 +0200 Subject: [PATCH 18/30] fix #1498 --- lib/queryBuilder/operations/eager/WhereInEagerOperation.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/queryBuilder/operations/eager/WhereInEagerOperation.js b/lib/queryBuilder/operations/eager/WhereInEagerOperation.js index 5f212fb07..92f55df16 100644 --- a/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +++ b/lib/queryBuilder/operations/eager/WhereInEagerOperation.js @@ -3,7 +3,7 @@ const promiseUtils = require('../../../utils/promiseUtils'); const { EagerOperation } = require('./EagerOperation'); -const { isMsSql, isOracle } = require('../../../utils/knexUtils'); +const { isMsSql, isOracle, isSqlite } = require('../../../utils/knexUtils'); const { asArray, flatten, chunk } = require('../../../utils/objectUtils'); const { ValidationErrorType } = require('../../../model/ValidationError'); const { createModifier } = require('../../../utils/createModifier'); @@ -25,6 +25,9 @@ class WhereInEagerOperation extends EagerOperation { return 2000; } else if (isOracle(knex)) { return 1000; + } else if (isSqlite(knex)) { + // SQLITE_MAX_VARIABLE_NUMBER is 999 by default + return 999; } else { // I'm sure there is some kind of limit for other databases too, but let's lower // this if someone ever hits those limits. From 07c0c7352f1a25528e5d45e37fd4434b5d94027a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Fri, 18 Oct 2019 11:01:17 +0300 Subject: [PATCH 19/30] try to fix randomly failing tests --- testUtils/TestSession.js | 8 +++++--- tests/integration/insertGraph.js | 4 +++- tests/integration/misc/#1455.js | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/testUtils/TestSession.js b/testUtils/TestSession.js index df5b30144..a66b8a587 100644 --- a/testUtils/TestSession.js +++ b/testUtils/TestSession.js @@ -44,7 +44,7 @@ class TestSession { static get namedFilters() { return { - 'orderById': builder => builder.orderBy('Model1.id'), + orderById: builder => builder.orderBy('Model1.id'), 'select:id': builder => builder.select(this.ref('id')), 'select:model1Prop1': builder => builder.select('model1Prop1'), 'select:model1Prop1Aliased': builder => builder.select('model1Prop1 as aliasedInFilter'), @@ -221,7 +221,8 @@ class TestSession { return knex.schema .createTable('Model1', table => { table.increments('id').primary(); - table.integer('model1Id') + table + .integer('model1Id') .index() .unsigned() .references('Model1.id') @@ -231,7 +232,8 @@ class TestSession { }) .createTable('model2', table => { table.increments('id_col').primary(); - table.integer('model1_id') + table + .integer('model1_id') .index() .unsigned() .references('Model1.id') diff --git a/tests/integration/insertGraph.js b/tests/integration/insertGraph.js index d2bf65fee..f0ff14792 100644 --- a/tests/integration/insertGraph.js +++ b/tests/integration/insertGraph.js @@ -1,4 +1,5 @@ const _ = require('lodash'); +const chai = require('chai'); const utils = require('../../lib/utils/knexUtils'); const expect = require('expect.js'); const Promise = require('bluebird'); @@ -570,7 +571,8 @@ module.exports = session => { .eager(eagerExpr) .findById(inserted.id) .then(fetched => { - expect(inserted.$toJson()).to.eql(fetched.$toJson()); + chai.expect(inserted.$toJson()).to.containSubset(fetched.$toJson()); + chai.expect(fetched.$toJson()).to.containSubset(inserted.$toJson()); }); }); }); diff --git a/tests/integration/misc/#1455.js b/tests/integration/misc/#1455.js index eee8fae26..9677327bc 100644 --- a/tests/integration/misc/#1455.js +++ b/tests/integration/misc/#1455.js @@ -55,6 +55,10 @@ module.exports = session => { static get useLimitInFirst() { return true; } + + static get concurrency() { + return 1; + } } class SetAttribute extends BaseModel { From 6e5ab83c57902ec8d258b4277d5d8a31feb41eaf Mon Sep 17 00:00:00 2001 From: tsabolov Date: Thu, 17 Oct 2019 09:01:13 +0200 Subject: [PATCH 20/30] Update query-examples.md Fixed `allowEager` link --- doc/guide/query-examples.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/guide/query-examples.md b/doc/guide/query-examples.md index 4a4c565bf..71715d34d 100644 --- a/doc/guide/query-examples.md +++ b/doc/guide/query-examples.md @@ -632,7 +632,7 @@ const people = await Person Arbitrary relation graphs can be inserted using the [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) method. This is best explained using examples, so check them out. -See the [allowInsert](/api/query-builder/mutate-methods.html#allowinsert) method if you need to limit which relations can be inserted using [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) method to avoid security issues. [allowInsert](/api/query-builder/mutate-methods.html#allowinsert) works like [allowEager](/api/query-builder/mutate-methods.html#allowinsert). +See the [allowInsert](/api/query-builder/mutate-methods.html#allowinsert) method if you need to limit which relations can be inserted using [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) method to avoid security issues. [allowInsert](/api/query-builder/mutate-methods.html#allowinsert) works like [allowEager](/api/query-builder/eager-methods.html#alloweager). If you are using Postgres the inserts are done in batches for maximum performance. On other databases the rows need to be inserted one at a time. This is because postgresql is the only database engine that returns the identifiers of all inserted rows and not just the first or the last one. From cf2f2e53e1bc83cf0f71ef721b4cc6e527e4f391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Gonz=C3=A1lez?= Date: Sat, 19 Oct 2019 17:44:02 -0300 Subject: [PATCH 21/30] fix: typo 'the the' --- doc/guide/models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/guide/models.md b/doc/guide/models.md index fc7d4081f..3abd5c887 100644 --- a/doc/guide/models.md +++ b/doc/guide/models.md @@ -6,7 +6,7 @@ Models can optionally define a [jsonSchema](/api/model/static-properties.html#st Each model must have an identifier column. The identifier column name can be set using the [idColumn](/api/model/static-properties.html#static-idcolumn) property. [idColumn](/api/model/static-properties.html#static-idcolumn) defaults to `"id"`. If your table's identifier is something else, you need to set [idColumn](/api/model/static-properties.html#static-idcolumn). Composite id can be set by giving an array of column names. Composite keys are first class citizens in objection. -In objection, all configuration is done through [Model](/api/model/) classes and there is no global configuration or state. There is no "objection instance". This allows you to create isolated components and for example to use multiple different databases with different configurations in one app. Most of the time you want the same configuration for all models and a good pattern is to create a `BaseModel` class and inherit all your models from that. You can then add all shared configuration to `BaseModel`. See the the static properties in [API Reference / Model](/api/model/static-properties.html#static-tablename) section for all available configuration options. +In objection, all configuration is done through [Model](/api/model/) classes and there is no global configuration or state. There is no "objection instance". This allows you to create isolated components and for example to use multiple different databases with different configurations in one app. Most of the time you want the same configuration for all models and a good pattern is to create a `BaseModel` class and inherit all your models from that. You can then add all shared configuration to `BaseModel`. See the static properties in [API Reference / Model](/api/model/static-properties.html#static-tablename) section for all available configuration options. Note that in addition to `idColumn`, you don't define properties, indexes or anything else related to database schema in the model. In objection, database schema is considered a separate concern and should be handled using [migrations](https://knexjs.org/#Migrations). The reasoning is that in every non-trivial project will need migrations anyway. Managing the schema in two places (model and migrations) only makes things more complex in the long run. From 12268cdbec2c67e598717c1a9fcaaf71a7abb57c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2019 17:46:56 +0000 Subject: [PATCH 22/30] Bump knex from 0.14.6 to 0.20.1 in /examples/minimal Bumps [knex](https://github.com/tgriesser/knex) from 0.14.6 to 0.20.1. - [Release notes](https://github.com/tgriesser/knex/releases) - [Changelog](https://github.com/knex/knex/blob/master/CHANGELOG.md) - [Commits](https://github.com/tgriesser/knex/compare/0.14.6...0.20.1) Signed-off-by: dependabot[bot] --- examples/minimal/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/minimal/package.json b/examples/minimal/package.json index d7fd3f030..0055e4d38 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -13,7 +13,7 @@ "author": "Sami Koskimäki", "license": "MIT", "dependencies": { - "knex": "^0.14.6", + "knex": "^0.20.1", "objection": "^1.6.6", "sqlite3": "^4.0.4" } From bd9beb199b059f6ffc5546cd0458c45cd435f85c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 3 Nov 2019 09:08:23 +0000 Subject: [PATCH 23/30] Bump knex from 0.14.6 to 0.20.1 in /examples/plugin Bumps [knex](https://github.com/tgriesser/knex) from 0.14.6 to 0.20.1. - [Release notes](https://github.com/tgriesser/knex/releases) - [Changelog](https://github.com/knex/knex/blob/master/CHANGELOG.md) - [Commits](https://github.com/tgriesser/knex/compare/0.14.6...0.20.1) Signed-off-by: dependabot[bot] --- examples/plugin/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plugin/package.json b/examples/plugin/package.json index 49b6efcb2..3ccacfc8b 100644 --- a/examples/plugin/package.json +++ b/examples/plugin/package.json @@ -13,7 +13,7 @@ "license": "MIT", "devDependencies": { "expect.js": "^0.3.1", - "knex": "^0.14.6", + "knex": "^0.20.1", "mocha": "^5.1.1", "objection": "^1.4.0", "sqlite3": "^4.0.0" From 2fd288b9823eee8986d7adb5471c787a28155029 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 3 Nov 2019 09:08:23 +0000 Subject: [PATCH 24/30] Bump knex from 0.14.6 to 0.20.1 in /examples/express-es6 Bumps [knex](https://github.com/tgriesser/knex) from 0.14.6 to 0.20.1. - [Release notes](https://github.com/tgriesser/knex/releases) - [Changelog](https://github.com/knex/knex/blob/master/CHANGELOG.md) - [Commits](https://github.com/tgriesser/knex/compare/0.14.6...0.20.1) Signed-off-by: dependabot[bot] --- examples/express-es6/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/express-es6/package.json b/examples/express-es6/package.json index 4421c5490..cfe411da1 100644 --- a/examples/express-es6/package.json +++ b/examples/express-es6/package.json @@ -17,7 +17,7 @@ "body-parser": "^1.18.2", "express": "^4.16.2", "express-promise-router": "^3.0.1", - "knex": "^0.14.6", + "knex": "^0.20.1", "lodash": "^4.17.4", "morgan": "^1.9.0", "objection": "^1.4.0", From 05df386b05dc0a5aac5f01330588c2d72c84099a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 3 Nov 2019 09:08:25 +0000 Subject: [PATCH 25/30] Bump knex from 0.14.6 to 0.20.1 in /examples/plugin-with-options Bumps [knex](https://github.com/tgriesser/knex) from 0.14.6 to 0.20.1. - [Release notes](https://github.com/tgriesser/knex/releases) - [Changelog](https://github.com/knex/knex/blob/master/CHANGELOG.md) - [Commits](https://github.com/tgriesser/knex/compare/0.14.6...0.20.1) Signed-off-by: dependabot[bot] --- examples/plugin-with-options/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plugin-with-options/package.json b/examples/plugin-with-options/package.json index f01f81de4..154fe66e0 100644 --- a/examples/plugin-with-options/package.json +++ b/examples/plugin-with-options/package.json @@ -13,7 +13,7 @@ "license": "MIT", "devDependencies": { "expect.js": "^0.3.1", - "knex": "^0.14.6", + "knex": "^0.20.1", "mocha": "^5.1.1", "objection": "^1.4.0", "sqlite3": "^4.0.4" From ed86515d0dc264617013023e12531aad2412d341 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 3 Nov 2019 09:08:28 +0000 Subject: [PATCH 26/30] Bump knex from 0.14.6 to 0.20.1 in /examples/express-ts Bumps [knex](https://github.com/tgriesser/knex) from 0.14.6 to 0.20.1. - [Release notes](https://github.com/tgriesser/knex/releases) - [Changelog](https://github.com/knex/knex/blob/master/CHANGELOG.md) - [Commits](https://github.com/tgriesser/knex/compare/0.14.6...0.20.1) Signed-off-by: dependabot[bot] --- examples/express-ts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/express-ts/package.json b/examples/express-ts/package.json index fdf121b13..d009205f7 100644 --- a/examples/express-ts/package.json +++ b/examples/express-ts/package.json @@ -18,7 +18,7 @@ "body-parser": "^1.18.2", "express": "^4.16.2", "express-promise-router": "^3.0.1", - "knex": "^0.14.6", + "knex": "^0.20.1", "lodash": "^4.17.4", "morgan": "^1.9.0", "objection": "^1.4.0", From 794a036b6e621af38631378eed85188dfb973d3f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 3 Nov 2019 09:08:30 +0000 Subject: [PATCH 27/30] Bump knex from 0.14.6 to 0.20.1 in /examples/express-es7 Bumps [knex](https://github.com/tgriesser/knex) from 0.14.6 to 0.20.1. - [Release notes](https://github.com/tgriesser/knex/releases) - [Changelog](https://github.com/knex/knex/blob/master/CHANGELOG.md) - [Commits](https://github.com/tgriesser/knex/compare/0.14.6...0.20.1) Signed-off-by: dependabot[bot] --- examples/express-es7/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/express-es7/package.json b/examples/express-es7/package.json index 6a9def694..f977d61a7 100644 --- a/examples/express-es7/package.json +++ b/examples/express-es7/package.json @@ -28,7 +28,7 @@ "body-parser": "^1.18.2", "express": "^4.16.2", "express-promise-router": "^3.0.1", - "knex": "^0.14.6", + "knex": "^0.20.1", "lodash": "^4.17.4", "morgan": "^1.9.0", "objection": "^1.4.0", From e8398f30fb8204a6e630ae25ecfe40241901d4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Wed, 13 Nov 2019 18:51:26 +0200 Subject: [PATCH 28/30] make v1 doc links work in github --- doc/README.md | 14 +- doc/api/model/instance-methods.md | 110 ++++----- doc/api/model/overview.md | 28 +-- doc/api/model/static-methods.md | 80 +++---- doc/api/model/static-properties.md | 54 ++--- doc/api/objection/README.md | 28 +-- doc/api/query-builder/README.md | 4 +- doc/api/query-builder/eager-methods.md | 58 ++--- doc/api/query-builder/find-methods.md | 208 +++++++++--------- doc/api/query-builder/join-methods.md | 40 ++-- doc/api/query-builder/mutate-methods.md | 138 ++++++------ doc/api/query-builder/other-methods.md | 114 +++++----- doc/api/query-builder/static-methods.md | 8 +- doc/api/types/README.md | 94 ++++---- doc/guide/contributing.md | 2 +- doc/guide/documents.md | 4 +- doc/guide/getting-started.md | 4 +- doc/guide/models.md | 8 +- doc/guide/plugins.md | 4 +- doc/guide/query-examples.md | 110 ++++----- doc/guide/relations.md | 4 +- doc/guide/transactions.md | 16 +- doc/guide/validation.md | 8 +- doc/recipes/composite-keys.md | 24 +- doc/recipes/custom-id-column.md | 2 +- doc/recipes/custom-query-builder.md | 6 +- doc/recipes/custom-validation.md | 8 +- doc/recipes/default-values.md | 4 +- doc/recipes/error-handling.md | 6 +- doc/recipes/extra-properties.md | 4 +- doc/recipes/joins.md | 2 +- doc/recipes/json-queries.md | 4 +- .../multitenancy-using-multiple-databases.md | 6 +- doc/recipes/paging.md | 6 +- doc/recipes/precedence-and-parentheses.md | 2 +- doc/recipes/raw-queries.md | 8 +- doc/recipes/relation-subqueries.md | 4 +- doc/recipes/returning-tricks.md | 2 +- .../snake-case-to-camel-case-conversion.md | 4 +- doc/recipes/subqueries.md | 8 +- doc/recipes/timestamps.md | 2 +- replace-v1-links.js | 41 ++++ 42 files changed, 661 insertions(+), 620 deletions(-) create mode 100644 replace-v1-links.js diff --git a/doc/README.md b/doc/README.md index 733f685f0..3cdc39234 100644 --- a/doc/README.md +++ b/doc/README.md @@ -15,20 +15,20 @@ Objection.js is built on an SQL query builder called [knex](http://knexjs.org). What objection.js gives you: - * **An easy declarative way of [defining models](/guide/models.html) and relationships between them** - * **Simple and fun way to [fetch, insert, update and delete](/guide/query-examples.html#basic-queries) objects using the full power of SQL** - * **Powerful mechanisms for [eager loading](/guide/query-examples.html#eager-loading), [inserting](/guide/query-examples.html#graph-inserts) and [upserting](/guide/query-examples.html#graph-upserts) object graphs** - * **Easy to use [transactions](/guide/transactions.html)** + * **An easy declarative way of [defining models](https://github.com/Vincit/objection.js/tree/v1/doc/guide/models.md) and relationships between them** + * **Simple and fun way to [fetch, insert, update and delete](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#basic-queries) objects using the full power of SQL** + * **Powerful mechanisms for [eager loading](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#eager-loading), [inserting](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-inserts) and [upserting](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts) object graphs** + * **Easy to use [transactions](https://github.com/Vincit/objection.js/tree/v1/doc/guide/transactions.md)** * **Official [TypeScript](https://github.com/Vincit/objection.js/blob/master/typings/objection/index.d.ts) support** - * **Optional [JSON schema](/guide/validation.html) validation** - * **A way to [store complex documents](/guide/documents.html) as single rows** + * **Optional [JSON schema](https://github.com/Vincit/objection.js/tree/v1/doc/guide/validation.md) validation** + * **A way to [store complex documents](https://github.com/Vincit/objection.js/tree/v1/doc/guide/documents.md) as single rows** What objection.js **doesn't** give you: * **A custom query DSL. SQL is used as a query language.** This doesn't mean you have to write SQL strings though. A query builder based on [knex](http://knexjs.org) is used to build the SQL. However, if the query builder fails you for some reason, raw SQL strings can be easily - written using the [raw](/api/objection/#raw) helper function. + written using the [raw](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#raw) helper function. * **Automatic database schema creation and migration from model definitions.** For simple things it is useful that the database schema is automatically generated from the model definitions, but usually just gets in your way when doing anything non-trivial. Objection.js leaves the schema related things diff --git a/doc/api/model/instance-methods.md b/doc/api/model/instance-methods.md index 01e4f4d14..3d848cc3b 100644 --- a/doc/api/model/instance-methods.md +++ b/doc/api/model/instance-methods.md @@ -22,7 +22,7 @@ transactionOrKnex|object|Optional transaction or knex instance for the query. Th Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|query builder +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|query builder ##### Examples @@ -73,9 +73,9 @@ console.log('person deleted'); const builder = person.$relatedQuery(relationName, transactionOrKnex); ``` -Use this to build a query that only affects the items related to an instance through a relation. By default, any fetched or inserted items are also stored to the owner model’s property named after the relation. See [relatedFindQueryMutates](/api/model/static-properties.html#static-relatedfindquerymutates) or [relatedInsertQueryMutates](/api/model/static-properties.html#static-relatedinsertquerymutates) to change this behaviour. +Use this to build a query that only affects the items related to an instance through a relation. By default, any fetched or inserted items are also stored to the owner model’s property named after the relation. See [relatedFindQueryMutates](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relatedfindquerymutates) or [relatedInsertQueryMutates](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relatedinsertquerymutates) to change this behaviour. -See the examples below and [here](/guide/query-examples.html#relation-queries). +See the examples below and [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#relation-queries). ##### Arguments @@ -88,7 +88,7 @@ transactionOrKnex|object|Optional transaction or knex instance for the query. Th Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|A query builder +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|A query builder ##### Examples @@ -206,7 +206,7 @@ If you start a query from this hook, make sure you specify `queryContext.transac Argument|Type|Description --------|----|------------------- -queryContext|Object|The context object of the insert query. See [context](/api/query-builder/other-methods.html#context). +queryContext|Object|The context object of the insert query. See [context](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context). ##### Return value @@ -253,7 +253,7 @@ You can return a promise from this function if you need to do asynchronous stuff Argument|Type|Description --------|----|------------------- -queryContext|Object|The context object of the insert query. See [context](/api/query-builder/other-methods.html#context). +queryContext|Object|The context object of the insert query. See [context](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context). ##### Return value @@ -298,14 +298,14 @@ you need to do update specific validation. This method is also called before a model is patched. Therefore all the model's properties may not exist. You can check if the update operation is a patch by checking the `opt.patch` boolean. -Inside the hook, `this` contains the values to be updated. If (and only if) the query is started for an existing model instance using [$query](/api/model/instance-methods.html#query), `opt.old` object contains the old values. The old values are never fetched from the database implicitly. For non-instance queries the `opt.old` object is `undefined`. See the examples. +Inside the hook, `this` contains the values to be updated. If (and only if) the query is started for an existing model instance using [$query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query), `opt.old` object contains the old values. The old values are never fetched from the database implicitly. For non-instance queries the `opt.old` object is `undefined`. See the examples. ##### Arguments Argument|Type|Description --------|----|------------------- -opt|[ModelOptions](/api/types/#type-modeloptions)|Update options. -queryContext|Object|The context object of the update query. See [context](/api/query-builder/other-methods.html#context). +opt|[ModelOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-modeloptions)|Update options. +queryContext|Object|The context object of the update query. See [context](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context). ##### Return value @@ -367,14 +367,14 @@ You can return a promise from this function if you need to do asynchronous stuff This method is also called after a model is patched. Therefore all the model's properties may not exist. You can check if the update operation is a patch by checking the `opt.patch` boolean. -Inside the hook, `this` contains the values to be updated. If (and only if) the query is started for an existing model instance using [$query](/api/model/instance-methods.html#query), `opt.old` object contains the old values. The old values are never fetched from the database implicitly. For non-instance queries the `opt.old` object is `undefined`. See the examples. +Inside the hook, `this` contains the values to be updated. If (and only if) the query is started for an existing model instance using [$query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query), `opt.old` object contains the old values. The old values are never fetched from the database implicitly. For non-instance queries the `opt.old` object is `undefined`. See the examples. ##### Arguments Argument|Type|Description --------|----|------------------- -opt|[ModelOptions](/api/types/#type-modeloptions)|Update options. -queryContext|Object|The context object of the update query. See [context](/api/query-builder/other-methods.html#context). +opt|[ModelOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-modeloptions)|Update options. +queryContext|Object|The context object of the update query. See [context](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context). ##### Return value @@ -435,14 +435,14 @@ Called before a model is deleted. You can return a promise from this function if you need to do asynchronous stuff. ::: warning -This method is only called for instance deletes started with [$query()](/api/model/instance-methods.html#query) method. All hooks are instance methods. For deletes there is no instance for which to call the hook, except when [$query()](/api/model/instance-methods.html#query) is used. Objection doesn't fetch the item just to call the hook for it to ensure predictable performance and prevent a whole class of concurrency bugs. +This method is only called for instance deletes started with [$query()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query) method. All hooks are instance methods. For deletes there is no instance for which to call the hook, except when [$query()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query) is used. Objection doesn't fetch the item just to call the hook for it to ensure predictable performance and prevent a whole class of concurrency bugs. ::: ##### Arguments Argument|Type|Description --------|----|------------------- -queryContext|Object|The context object of the update query. See [context](/api/query-builder/other-methods.html#context). +queryContext|Object|The context object of the update query. See [context](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context). ##### Return value @@ -485,14 +485,14 @@ Called after a model is deleted. You can return a promise from this function if you need to do asynchronous stuff. ::: warning -This method is only called for instance deletes started with [$query()](/api/model/instance-methods.html#query) method. All hooks are instance methods. For deletes there is no instance for which to call the hook, except when [$query()](/api/model/instance-methods.html#query) is used. Objection doesn't fetch the item just to call the hook for it to ensure predictable performance and prevent a whole class of concurrency bugs. +This method is only called for instance deletes started with [$query()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query) method. All hooks are instance methods. For deletes there is no instance for which to call the hook, except when [$query()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query) is used. Objection doesn't fetch the item just to call the hook for it to ensure predictable performance and prevent a whole class of concurrency bugs. ::: ##### Arguments Argument|Type|Description --------|----|------------------- -queryContext|Object|The context object of the update query. See [context](/api/query-builder/other-methods.html#context). +queryContext|Object|The context object of the update query. See [context](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context). ##### Return value @@ -539,7 +539,7 @@ You can return a promise from this function if you need to do asynchronous stuff Argument|Type|Description --------|----|------------------- -queryContext|Object|The context object of the update query. See [context](/api/query-builder/other-methods.html#context). +queryContext|Object|The context object of the update query. See [context](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context). ##### Return value @@ -573,19 +573,19 @@ const clone = modelInstance.$clone(options); Returns a (deep) copy of a model instance. -If the item to be cloned has instances of [Model](/api/model/) as properties (or arrays of them) they are cloned using their `$clone()` method. A shallow copy without relations can be created by passing the `shallow: true` option. +If the item to be cloned has instances of [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) as properties (or arrays of them) they are cloned using their `$clone()` method. A shallow copy without relations can be created by passing the `shallow: true` option. ##### Arguments Argument|Type|Description --------|----|-------------------- -opt|[CloneOptions](/api/types/#type-cloneoptions)|Optional options +opt|[CloneOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-cloneoptions)|Optional options ##### Return value Type|Description ----|----------------------------- -[Model](/api/model/)|Deep clone of `this` +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|Deep clone of `this` ##### Examples @@ -601,13 +601,13 @@ const jsonObj = modelInstance.toJSON(opt); Exports this model as a JSON object. -See [this section](/api/model/overview.html#model-data-lifecycle) for more information. +See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/overview.md#model-data-lifecycle) for more information. ##### Arguments Argument|Type|Description --------|----|-------------------- -opt|[ToJsonOptions](/api/types/#type-tojsonoptions)|Optional options +opt|[ToJsonOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-tojsonoptions)|Optional options ##### Return value @@ -627,7 +627,7 @@ const onlySomeVirtuals = modelInstance.toJSON({ virtuals: ['fullName'] }); ## $toJson() -Alias for [toJSON](/api/model/instance-methods.html#tojson) +Alias for [toJSON](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#tojson) ## $toDatabaseJson() @@ -639,7 +639,7 @@ Exports this model as a database JSON object. This method is called internally to convert a model into a database row. -See [this section](/api/model/overview.html#model-data-lifecycle) for more information. +See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/overview.md#model-data-lifecycle) for more information. ##### Return value @@ -660,9 +660,9 @@ class Person extends Model { } ``` -This is called when a [Model](/api/model/) instance is created from a database JSON object. This method converts the JSON object from the database format to the internal format. +This is called when a [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) instance is created from a database JSON object. This method converts the JSON object from the database format to the internal format. -You can override this method to carry out whatever conversions you want for the data when it's fetched from the database, before it's converted into a model instance. See [this section](/api/model/overview.html#model-data-lifecycle) for more information. +You can override this method to carry out whatever conversions you want for the data when it's fetched from the database, before it's converted into a model instance. See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/overview.md#model-data-lifecycle) for more information. There are a couple of requirements for the implementation: @@ -695,9 +695,9 @@ class Person extends Model { } ``` -This is called when a [Model](/api/model/) is converted to database format. +This is called when a [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) is converted to database format. -You can override this method to carry out whatever conversions you want for the data when it's being sent to the database driver. See [this section](/api/model/overview.html#model-data-lifecycle) for more information. +You can override this method to carry out whatever conversions you want for the data when it's being sent to the database driver. See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/overview.md#model-data-lifecycle) for more information. There are a couple of requirements for the implementation: @@ -730,9 +730,9 @@ class Person extends Model { } ``` -This is called when a [Model](/api/model/) is created from a JSON object. Converts the JSON object from the external format to the internal format. +This is called when a [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) is created from a JSON object. Converts the JSON object from the external format to the internal format. -You can override this method to carry out whatever conversions you want for the data when a model instance is being created from external data. See [this section](/api/model/overview.html#model-data-lifecycle) for more information. +You can override this method to carry out whatever conversions you want for the data when a model instance is being created from external data. See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/overview.md#model-data-lifecycle) for more information. There are a couple of requirements for the implementation: @@ -745,7 +745,7 @@ There are a couple of requirements for the implementation: Argument|Type|Description --------|----|------------------- json|Object|The JSON POJO in external format -opt|[ModelOptions](/api/types/#type-modeloptions)|Optional options +opt|[ModelOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-modeloptions)|Optional options ##### Return value @@ -766,9 +766,9 @@ class Person extends Model { } ``` -This is called when a [Model](/api/model/) is converted to JSON. Converts the JSON object from the internal format to the external format. +This is called when a [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) is converted to JSON. Converts the JSON object from the internal format to the external format. -You can override this method to carry out whatever conversions you want for the data when a model instance is being converted into external representation. See [this section](/api/model/overview.html#model-data-lifecycle) for more information. +You can override this method to carry out whatever conversions you want for the data when a model instance is being converted into external representation. See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/overview.md#model-data-lifecycle) for more information. There are a couple of requirements for the implementation: @@ -803,13 +803,13 @@ Validates the JSON before setting values. Argument|Type|Description --------|----|------------------- json|Object|The JSON POJO to set -opt|[ModelOptions](/api/types/#type-modeloptions)|Optional options +opt|[ModelOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-modeloptions)|Optional options ##### Return value Type|Description ----|----------------------------- -[Model](/api/model/)|`this` for chaining +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|`this` for chaining ## $setDatabaseJson() @@ -829,7 +829,7 @@ json|Object|The JSON POJO in database format Type|Description ----|----------------------------- -[Model](/api/model/)|`this` for chaining +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|`this` for chaining ## $set() @@ -839,7 +839,7 @@ modelInstance.$set(json); Sets the values from another model instance or object. -Unlike [$setJson](/api/model/instance-methods.html#setjson), this doesn't call any [$parseJson](/api/model/instance-methods.html#parsejson) hooks or validate the input. This simply sets each value in the object to this object. +Unlike [$setJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#setjson), this doesn't call any [$parseJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#parsejson) hooks or validate the input. This simply sets each value in the object to this object. ##### Arguments @@ -851,7 +851,7 @@ obj|Object|The values to set Type|Description ----|----------------------------- -[Model](/api/model/)|`this` for chaining +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|`this` for chaining ## $setRelated() @@ -865,14 +865,14 @@ Sets related models to a corresponding property in the object. Argument|Type|Description --------|----|------------------- -relation|string|[Relation](/api/types/#class-relation)|Relation name or a relation instance to set. -relatedModels|[Model](/api/model/)|[Model](/api/model/)[]|Models to set. +relation|string|[Relation](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-relation)|Relation name or a relation instance to set. +relatedModels|[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)[]|Models to set. ##### Return value Type|Description ----|----------------------------- -[Model](/api/model/)|`this` for chaining +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|`this` for chaining ##### Examples @@ -898,14 +898,14 @@ Appends related models to a corresponding property in the object. Argument|Type|Description --------|----|------------------- -relation|string|[Relation](/api/types/#class-relation)|Relation name or a relation instance to append to. -relatedModels|[Model](/api/model/)|[Model](/api/model/)[]|Models to append. +relation|string|[Relation](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-relation)|Relation name or a relation instance to append to. +relatedModels|[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)[]|Models to append. ##### Return value Type|Description ----|----------------------------- -[Model](/api/model/)|`this` for chaining +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|`this` for chaining ##### Examples @@ -932,7 +932,7 @@ const builder = person.$loadRelated( ); ``` -Shortcut for [Person.loadRelated(person, expression, filter, transactionOrKnex)](/api/model/static-methods.html#static-loadrelated) +Shortcut for [Person.loadRelated(person, expression, filter, transactionOrKnex)](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-loadrelated) ## $traverse() @@ -940,7 +940,7 @@ Shortcut for [Person.loadRelated(person, expression, filter, transactionOrKnex)] person.$traverse(filterConstructor, callback) ``` -Shortcut for [Model.traverse(filterConstructor, this, callback)](/api/model/static-methods.html#static-traverse). +Shortcut for [Model.traverse(filterConstructor, this, callback)](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-traverse). ## $traverseAsync() @@ -948,7 +948,7 @@ Shortcut for [Model.traverse(filterConstructor, this, callback)](/api/model/stat person.$traverseAsync(filterConstructor, callback) ``` -Shortcut for [Model.traverseAsync(filterConstructor, this, callback)](/api/model/static-methods.html#static-traverseasync). +Shortcut for [Model.traverseAsync(filterConstructor, this, callback)](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-traverseasync). ## $knex() @@ -956,7 +956,7 @@ Shortcut for [Model.traverseAsync(filterConstructor, this, callback)](/api/model const knex = person.$knex() ``` -Shortcut for [Person.knex()](/api/model/static-methods.html#static-knex). +Shortcut for [Person.knex()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-knex). ## $transaction() @@ -964,7 +964,7 @@ Shortcut for [Person.knex()](/api/model/static-methods.html#static-knex). const knex = person.$transaction() ``` -Shortcut for [Person.knex()](/api/model/static-methods.html#static-knex). +Shortcut for [Person.knex()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-knex). ## $id() @@ -1013,7 +1013,7 @@ Argument|Type|Description --------|----|------------------- jsonSchema|Object|A deep clone of this class's jsonSchema json|Object|The JSON object to be validated -opt|[ModelOptions](/api/types/type-modeloptions)|Optional options +opt|[ModelOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/type-modeloptions)|Optional options ##### Return value @@ -1042,7 +1042,7 @@ You can do further validation here and throw an error if something goes wrong. Argument|Type|Description --------|----|------------------- json|Object|The JSON object to be validated -opt|[ModelOptions](/api/types/type-modeloptions)|Optional options +opt|[ModelOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/type-modeloptions)|Optional options ## $validate() @@ -1052,14 +1052,14 @@ modelInstance.$validate(); Validates the model instance. -Calls [$beforeValidate](/api/model/instance-methods.html#beforevalidate) and [$afterValidate](/api/model/instance-methods.html#aftervalidate) methods. This method is called automatically from [fromJson](/api/model/static-methods.html#static-fromjson) and [$setJson](/api/model/instance-methods.html#setjson) methods. This method can also be +Calls [$beforeValidate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforevalidate) and [$afterValidate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#aftervalidate) methods. This method is called automatically from [fromJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-fromjson) and [$setJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#setjson) methods. This method can also be called explicitly when needed. ##### Throws Type|Description ----|----------------------------- -[ValidationError](/api/types/#class-validationerror)|If validation fails. +[ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror)|If validation fails. ## $omit() @@ -1079,7 +1079,7 @@ keys|string
string[]
Object<string, boolean>|keys to omit Type|Description ----|----------------------------- -[Model](/api/model/)|`this` for chaining +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|`this` for chaining ##### Examples @@ -1130,7 +1130,7 @@ keys|string
string[]
Object<string, boolean>|keys to pick Type|Description ----|----------------------------- -[Model](/api/model/)|`this` for chaining +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|`this` for chaining ##### Examples diff --git a/doc/api/model/overview.md b/doc/api/model/overview.md index e35cc5828..d03a05c86 100644 --- a/doc/api/model/overview.md +++ b/doc/api/model/overview.md @@ -10,16 +10,16 @@ For the purposes of this explanation, let’s define three data layouts: Whenever data is converted from one layout to another, converter methods are called: -1. `database` -> [$parseDatabaseJson](/api/model/instance-methods.html#parsedatabasejson) -> `internal` -2. `internal` -> [$formatDatabaseJson](/api/model/instance-methods.html#formatdatabasejson) -> `database` -3. `external` -> [$parseJson](/api/model/instance-methods.html#parsejson) -> `internal` -4. `internal` -> [$formatJson](/api/model/instance-methods.html#formatjson) -> `external` +1. `database` -> [$parseDatabaseJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#parsedatabasejson) -> `internal` +2. `internal` -> [$formatDatabaseJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#formatdatabasejson) -> `database` +3. `external` -> [$parseJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#parsejson) -> `internal` +4. `internal` -> [$formatJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#formatjson) -> `external` -So for example when the results of a query are read from the database the data goes through the [$parseDatabaseJson](/api/model/instance-methods.html#parsedatabasejson) method. When data is written to database it goes through the [$formatDatabaseJson](/api/model/instance-methods.html#formatdatabasejson) method. +So for example when the results of a query are read from the database the data goes through the [$parseDatabaseJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#parsedatabasejson) method. When data is written to database it goes through the [$formatDatabaseJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#formatdatabasejson) method. -Similarly when you give data for a query (for example [`query().insert(req.body)`](/api/query-builder/mutate-methods.html#insert)) or create a model explicitly using [`Model.fromJson(obj)`](/api/model/static-methods.html#static-fromjson) the [$parseJson](/api/model/instance-methods.html#parsejson) method is invoked. When you call [`model.toJSON()`](/api/model/instance-methods.html#tojson) or [`model.$toJson()`](/api/model/instance-methods.html#tojson) the [$formatJson](/api/model/instance-methods.html#formatjson) is called. +Similarly when you give data for a query (for example [`query().insert(req.body)`](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insert)) or create a model explicitly using [`Model.fromJson(obj)`](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-fromjson) the [$parseJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#parsejson) method is invoked. When you call [`model.toJSON()`](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#tojson) or [`model.$toJson()`](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#tojson) the [$formatJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#formatjson) is called. -Note: Most libraries like [express](http://expressjs.com/en/index.html) and [koa](https://koajs.com/) automatically call the [toJSON](/api/model/instance-methods.html#tojson) method when you pass the model instance to methods like `response.json(model)`. You rarely need to call [toJSON()](/api/model/instance-methods.html#tojson) or [$toJson()](/api/model/instance-methods.html#tojson) explicitly. +Note: Most libraries like [express](http://expressjs.com/en/index.html) and [koa](https://koajs.com/) automatically call the [toJSON](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#tojson) method when you pass the model instance to methods like `response.json(model)`. You rarely need to call [toJSON()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#tojson) or [$toJson()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#tojson) explicitly. By overriding the lifecycle methods, you can have different layouts for the data in database and when exposed to the outside world. @@ -27,10 +27,10 @@ All instance methods of models are prefixed with `$` letter so that they won’t In addition to these data formatting hooks, Model also has query lifecycle hooks -* [$beforeUpdate](/api/model/instance-methods.html#beforeupdate) -* [$afterUpdate](/api/model/instance-methods.html#afterupdate) -* [$beforeInsert](/api/model/instance-methods.html#beforeinsert) -* [$afterInsert](/api/model/instance-methods.html#afterinsert) -* [$beforeDelete](/api/model/instance-methods.html#beforedelete) -* [$afterDelete](/api/model/instance-methods.html#afterdelete) -* [$afterGet](/api/model/instance-methods.html#afterget) +* [$beforeUpdate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforeupdate) +* [$afterUpdate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#afterupdate) +* [$beforeInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforeinsert) +* [$afterInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#afterinsert) +* [$beforeDelete](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforedelete) +* [$afterDelete](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#afterdelete) +* [$afterGet](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#afterget) diff --git a/doc/api/model/static-methods.md b/doc/api/model/static-methods.md index f24956597..0201ce208 100644 --- a/doc/api/model/static-methods.md +++ b/doc/api/model/static-methods.md @@ -9,7 +9,7 @@ Creates a query builder for the model's table. All query builders are created using this function, including `$query`, `$relatedQuery` and `relatedQuery`. That means you can modify each query by overriding this method for your model class. -See the [query examples](/guide/query-examples.html) section for more examples. +See the [query examples](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md) section for more examples. #### Arguments @@ -21,7 +21,7 @@ transactionOrKnex|object|Optional transaction or knex instance for the query. Th Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|The created query builder +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|The created query builder #### Examples @@ -133,7 +133,7 @@ Creates a subquery for a relation. This query can only be used as a subquery and therefore there is no need to ever pass a transaction or a knex instance to it. It will always inherit its parent query's transaction because it is compiled and executed as a part of the parent query. -See the examples below. There are also more examples in the [Relation Subqueries recipe](/recipes/relation-subqueries.html). +See the examples below. There are also more examples in the [Relation Subqueries recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/relation-subqueries.md). ##### Arguments @@ -145,7 +145,7 @@ relationName|string|The name of the relation to create subquery for. Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|The created query builder +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|The created query builder ##### Examples @@ -198,7 +198,7 @@ Get/Set the knex instance for a model class. Subclasses inherit the connection. A system-wide knex instance can thus be set by calling `objection.Model.knex(knex)`. This works even after subclasses have been created. -If you want to use multiple databases, you can instead pass the knex instance to each individual query or use the [bindKnex](/api/model/static-methods.html#static-bindknex) method. +If you want to use multiple databases, you can instead pass the knex instance to each individual query or use the [bindKnex](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-bindknex) method. ##### Examples @@ -229,9 +229,9 @@ const BoundPerson = Person.bindKnex(transactionOrKnex); Creates an anonymous model subclass class that is bound to the given knex instance or transaction. -This method can be used to bind a Model subclass to multiple databases for example in a multi-tenant system. See the [multi tenancy recipe](/recipes/multitenancy-using-multiple-databases.html) for more info. +This method can be used to bind a Model subclass to multiple databases for example in a multi-tenant system. See the [multi tenancy recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/multitenancy-using-multiple-databases.md) for more info. -Also check out the the [model binding pattern for transactions](/guide/transactions.html#binding-models-to-a-transaction) which internally uses `bindKnex`. +Also check out the the [model binding pattern for transactions](https://github.com/Vincit/objection.js/tree/v1/doc/guide/transactions.md#binding-models-to-a-transaction) which internally uses `bindKnex`. ##### Arguments @@ -285,7 +285,7 @@ console.log(models[0] instanceof BoundModel2); // --> true ## `static` bindTransaction() -Alias for [bindKnex](/api/model/static-methods.html#static-bindknex). +Alias for [bindKnex](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-bindknex). ##### Examples @@ -333,22 +333,22 @@ const person = Person.fromJson(json, opt); Creates a model instance from a POJO (Plain Old Javascript Object). -The object is checked against [jsonSchema](/api/model/static-properties.html#static-jsonschema) if a schema is provided and an exception is thrown on failure. +The object is checked against [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema) if a schema is provided and an exception is thrown on failure. -The `json` object is also passed through the [$parseJson](/api/model/instance-methods.html#parsejson) hook before the model instance is created. See [this section](/api/model/overview.html#model-data-lifecycle) for more info. +The `json` object is also passed through the [$parseJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#parsejson) hook before the model instance is created. See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/overview.md#model-data-lifecycle) for more info. ##### Arguments Argument|Type|Description --------|----|------------------- json|Object|The JSON object from which to create the model. -opt|[ModelOptions](/api/types/#type-modeloptions)|Update options. +opt|[ModelOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-modeloptions)|Update options. ##### Return value Type|Description ----|----------------------------- -[Model](/api/model/)|The created model instance +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The created model instance ##### Examples @@ -375,7 +375,7 @@ const person = Person.fromDatabaseJson(row); Creates a model instance from a JSON object send by the database driver. -Unlike [fromJson](/api/model/static-methods.html#static-fromjson), this method doesn't validate the input. The input is expected to be in the database format as explained [here](/api/model/overview.html#model-data-lifecycle). +Unlike [fromJson](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-fromjson), this method doesn't validate the input. The input is expected to be in the database format as explained [here](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/overview.md#model-data-lifecycle). ##### Arguments @@ -387,7 +387,7 @@ row|Object|A database row. Type|Description ----|----------------------------- -[Model](/api/model/)|The created model instance +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The created model instance ## `static` modifierNotFound() @@ -405,7 +405,7 @@ class BaseModel extends Model { ``` Handles modifiers that are not recognized by the various mechanisms that can specify -them, such as [modify](/api/query-builder/other-methods.html#modify) and [applyModifier](/api/query-builder/other-methods.html#applymodifier), as well as the use of modifiers in eager expressions (see [RelationExpression](/api/types/#type-relationexpression)) and in relations (see [RelationMapping](/api/types/#type-relationmapping)). +them, such as [modify](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#modify) and [applyModifier](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#applymodifier), as well as the use of modifiers in eager expressions (see [RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression)) and in relations (see [RelationMapping](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationmapping)). By default, the static `modifierNotFound()` hook throws a `ModifierNotFoundError` error. If a model class overrides the hook, it can decide to handle the modifer through the passed `builder` instance, or call the hook's definition in the super class to still throw the error. @@ -413,7 +413,7 @@ By default, the static `modifierNotFound()` hook throws a `ModifierNotFoundError Argument|Type|Description --------|----|------------------- -builder|[QueryBuilder](/api/query-builder/)|The query builder on which to apply the modifier. +builder|[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|The query builder on which to apply the modifier. modifier|string|The name of the unknown modifier. ## `static` createValidator() @@ -426,11 +426,11 @@ class BaseModel extends Model { } ``` -Creates an instance of a [Validator](/api/types/#class-validator) that is used to do all validation related stuff. This method is called only once per model class. +Creates an instance of a [Validator](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validator) that is used to do all validation related stuff. This method is called only once per model class. -You can override this method to return an instance of your custom validator. The custom validator doesn't need to be based on the `jsonSchema`. It can be anything at all as long as it implements the [Validator](/api/types/#class-validator) interface. +You can override this method to return an instance of your custom validator. The custom validator doesn't need to be based on the `jsonSchema`. It can be anything at all as long as it implements the [Validator](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validator) interface. -If you want to use the default json schema based [AjvValidator](/api/types/#class-ajvvalidator) but want to modify it, you can use the `objection.AjvValidator` constructor. See the default implementation example. +If you want to use the default json schema based [AjvValidator](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-ajvvalidator) but want to modify it, you can use the `objection.AjvValidator` constructor. See the default implementation example. If you want to share the same validator instance between multiple models, that's completely fine too. Simply implement `createValidator` so that it always returns the same object instead of creating a new one. @@ -480,20 +480,20 @@ class BaseModel extends Model { } ``` -Creates an error thrown by [throwIfNotFound](/api/query-builder/other-methods.html#throwifnotfound) method. You can override this +Creates an error thrown by [throwIfNotFound](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#throwifnotfound) method. You can override this to throw any error you want. ##### Arguments Argument|Type|Description --------|----|------------------- -queryContext|Object|The context object of query that produced the empty result. See [context](/api/query-builder/other-methods.html#context). +queryContext|Object|The context object of query that produced the empty result. See [context](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context). ##### Return value Type|Description ----|----------------------------- -`Error`|The created error. [NotFoundError](/api/types/#class-notfounderror) by default. +`Error`|The created error. [NotFoundError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-notfounderror) by default. ##### Examples @@ -523,7 +523,7 @@ Creates an error thrown when validation fails for a model. You can override this Type|Description ----|----------------------------- -`Error`|The created error. [ValidationError](/api/types/#class-validationerror) by default. +`Error`|The created error. [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror) by default. ## `static` loadRelated() @@ -536,22 +536,22 @@ const queryBuilder = Person.loadRelated( ); ``` -Load related models for a set of models using a [RelationExpression](/api/types/#type-relationexpression). +Load related models for a set of models using a [RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression). ##### Arguments Argument|Type|Description --------|----|------------------- -models|Array<[Model](/api/model/)|Object>|Model instances for which to fetch the relations. Can be an array of model instances, array of POJOs, a single model instance or a single POJO. -expression|string|[RelationExpression](/api/types/#type-relationexpression)|The relation expression -modifiers|Object<string, function([QueryBuilder](/api/query-builder/))>|Optional modifiers +models|Array<[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|Object>|Model instances for which to fetch the relations. Can be an array of model instances, array of POJOs, a single model instance or a single POJO. +expression|string|[RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression)|The relation expression +modifiers|Object<string, function([QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/))>|Optional modifiers transactionOrKnex|object|Optional transaction or knex instance for the query. This can be used to specify a transaction or even a different database. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|The created query builder +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|The created query builder ##### Examples @@ -601,8 +601,8 @@ In the second example the traverser function is only called for `Person` instanc Argument|Type|Description --------|----|------------------- filterConstructor|function|If this optional constructor is given, the `traverser` is only called for models for which `model instanceof filterConstructor` returns true. -models|[Model](/api/model/)|[Model](/api/model/)[]|The model(s) whose relation trees to traverse. -traverser|function([Model](/api/model/), string, string)|The traverser function that is called for each model. The first argument is the model itself. If the model is in a relation of some other model the second argument is the parent model and the third argument is the name of the relation. +models|[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)[]|The model(s) whose relation trees to traverse. +traverser|function([Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/), string, string)|The traverser function that is called for each model. The first argument is the model itself. If the model is in a relation of some other model the second argument is the parent model and the third argument is the name of the relation. ##### Examples @@ -642,7 +642,7 @@ await Person.traverseAsync(person, async (model, parentModel, relationName) => { const relations = Person.getRelations(); ``` -Returns a [Relation](/api/types/#class-relation) object for each relation defined in [relationMappings](/api/model/static-properties.html#static-relationmappings). +Returns a [Relation](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-relation) object for each relation defined in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings). This method is mainly useful for plugin developers and for other generic usages. @@ -650,7 +650,7 @@ This method is mainly useful for plugin developers and for other generic usages. Type|Description ----|----------------------------- -Object<string, [Relation](/api/types/#class-relation)>|Object whose keys are relation names and values are [Relation](/api/types/#class-relation) instances. +Object<string, [Relation](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-relation)>|Object whose keys are relation names and values are [Relation](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-relation) instances. ## `static` columnNameToPropertyName() @@ -717,23 +717,23 @@ const metadata = await Person.fetchTableMetadata(opt); Fetches and caches the table metadata. -Most of the time objection doesn't need this metadata, but some methods like [joinEager](/api/query-builder/eager-methods.html#joineager) do. This method is called by objection when the metadata is needed. The result is cached and after the first call the cached promise is returned and no queries are executed. +Most of the time objection doesn't need this metadata, but some methods like [joinEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#joineager) do. This method is called by objection when the metadata is needed. The result is cached and after the first call the cached promise is returned and no queries are executed. Because objection uses this on demand, the first query that needs this information can have unpredicable performance. If that's a problem, you can call this method for each of your models during your app's startup. -If you've implemented [tableMetadata](/api/model/static-methods.html#static-tablemetadata) method to return a custom metadata object, this method doesn't execute database queries, but returns `Promise.resolve(this.tableMetadata())` instead. +If you've implemented [tableMetadata](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-tablemetadata) method to return a custom metadata object, this method doesn't execute database queries, but returns `Promise.resolve(this.tableMetadata())` instead. ##### Arguments Argument|Type|Description --------|----|------------------- -opt|[TableMetadataFetchOptions](/api/types/#type-tablemetadatafetchoptions)|Optional options +opt|[TableMetadataFetchOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-tablemetadatafetchoptions)|Optional options ##### Return value Type|Description ----|----------------------------- -Promise<[TableMetadata](/api/types/#type-tablemetadata)>|The table metadata object +Promise<[TableMetadata](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-tablemetadata)>|The table metadata object ## `static` tableMetadata() @@ -744,21 +744,21 @@ const metadata = Person.tableMetadata(opt); Synchronously returns the table metadata object from the cache. You can override this method to return a custom object if you don't want objection to use -[fetchTableMetadata](/api/model/static-methods.html#static-fetchtablemetadata). +[fetchTableMetadata](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-fetchtablemetadata). -See [fetchTableMetadata](/api/model/static-methods.html#static-fetchtablemetadata) for more information. +See [fetchTableMetadata](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-fetchtablemetadata) for more information. ##### Arguments Argument|Type|Description --------|----|------------------- -opt|[TableMetadataOptions](/api/types/#type-tablemetadataoptions)|Optional options +opt|[TableMetadataOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-tablemetadataoptions)|Optional options ##### Return value Type|Description ----|----------------------------- -[TableMetadata](/api/types/#type-tablemetadata)|The table metadata object +[TableMetadata](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-tablemetadata)|The table metadata object diff --git a/doc/api/model/static-properties.md b/doc/api/model/static-properties.md index 7f0811f4f..d31ac564c 100644 --- a/doc/api/model/static-properties.md +++ b/doc/api/model/static-properties.md @@ -18,19 +18,19 @@ Each model must set this. This property defines the relations to other models. -relationMappings is an object (or a function that returns an object) whose keys are relation names and values are [RelationMapping](/api/types/#type-relationmapping) instances. The `join` property in addition to the relation type define how the models are related to one another. The `from` and `to` properties of the `join` object define the database columns through which the models are associated. Note that neither of these columns need to be primary keys. They can be any columns. In fact they can even be fields inside JSON columns (using the [ref](/api/objection/#ref) helper). In the case of ManyToManyRelation also the join table needs to be defined. This is done using the `through` object. +relationMappings is an object (or a function that returns an object) whose keys are relation names and values are [RelationMapping](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationmapping) instances. The `join` property in addition to the relation type define how the models are related to one another. The `from` and `to` properties of the `join` object define the database columns through which the models are associated. Note that neither of these columns need to be primary keys. They can be any columns. In fact they can even be fields inside JSON columns (using the [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref) helper). In the case of ManyToManyRelation also the join table needs to be defined. This is done using the `through` object. The `modelClass` passed to the relation mappings is the class of the related model. It can be one of the following: 1. A model class constructor 2. An absolute path to a module that exports a model class -3. A path relative to one of the paths in [modelPaths](/api/model/static-properties.html#static-modelpaths) array. +3. A path relative to one of the paths in [modelPaths](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modelpaths) array. The file path versions are handy for avoiding require loops. Further reading: - * [the relation guide](/guide/relations.html) - * [RelationMapping](/api/types/#type-relationmapping) + * [the relation guide](https://github.com/Vincit/objection.js/tree/v1/doc/guide/relations.md) + * [RelationMapping](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationmapping) ##### Examples @@ -136,9 +136,9 @@ Must follow [JSON Schema](http://json-schema.org) specification. If null no vali ##### Read more -* [$validate](/api/model/instance-methods.html#validate) -* [jsonAttributes](/api/model/static-properties.html#static-jsonattributes) -* [custom validation recipe](/recipes/custom-validation.html) +* [$validate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#validate) +* [jsonAttributes](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonattributes) +* [custom validation recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/custom-validation.md) ##### Examples @@ -194,7 +194,7 @@ class Person extends Model { } ``` -Getters and methods listed here are serialized with real properties when [toJSON](/api/model/instance-methods.html#tojson) is called. Virtual attribute methods and getters must be synchronous. +Getters and methods listed here are serialized with real properties when [toJSON](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#tojson) is called. Virtual attribute methods and getters must be synchronous. The virtual values are not written to database. Only the "external" JSON format will contain them. @@ -232,7 +232,7 @@ console.log(pojo.fullName) // --> 'Jennifer Aniston' console.log(pojo.isFemale) // --> true ``` -You can also pass options to [toJSON](/api/model/instance-methods.html#tojson) to only serialize a subset of virtual attributes. In fact, when the `virtuals` option is used, the attributes don't even need to be listed in `virtualAttributes`. +You can also pass options to [toJSON](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#tojson) to only serialize a subset of virtual attributes. In fact, when the `virtuals` option is used, the attributes don't even need to be listed in `virtualAttributes`. ```js const pojo = person.toJSON({ virtuals: ['fullName'] }) @@ -240,7 +240,7 @@ const pojo = person.toJSON({ virtuals: ['fullName'] }) ## `static` modifiers -Reusable query building functions that can be used in any [eager query](/api/query-builder/eager-methods.html#eager), using [modify](/api/query-builder/other-methods.html#modify) method and in many other places. +Reusable query building functions that can be used in any [eager query](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager), using [modify](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#modify) method and in many other places. ```js class Movie extends Model { @@ -276,7 +276,7 @@ Person .eager('[movies(goodMovies, orderByName).actors, pets(dogs)]') ``` -Modifiers can also be used through [modifyEager](/api/query-builder/other-methods.html#modifyeager): +Modifiers can also be used through [modifyEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#modifyeager): ```js Person @@ -288,7 +288,7 @@ Person ## `static` namedFilters -An alias for [modifiers](/api/model/static-properties.html#static-modifiers) +An alias for [modifiers](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modifiers) ## `static` modelPaths @@ -302,7 +302,7 @@ class Person extends Model { A list of paths from which to search for models for relations. -A model class can be defined for a relation in [relationMappings](/api/model/static-properties.html#static-relationmappings) as +A model class can be defined for a relation in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) as 1. A model class constructor 2. An absolute path to a module that exports a model class @@ -368,7 +368,7 @@ Properties that should be saved to database as JSON strings. The properties listed here are serialized to JSON strings upon insertion/update to the database and parsed back to objects when models are read from the database. Combined with the postgresql's json or jsonb data type, this is a powerful way of representing documents as single database rows. -If this property is left unset all properties declared as objects or arrays in the [jsonSchema](/api/model/static-properties.html#static-jsonschema) are implicitly added to this list. +If this property is left unset all properties declared as objects or arrays in the [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema) are implicitly added to this list. ## `static` cloneObjectAttributes @@ -404,8 +404,8 @@ The mappers to use to convert column names to property names in code. Further reading: - * [snakeCaseMappers](/api/objection/#snakecasemappers) - * [snake_case to camelCase conversion recipe](/recipes/snake-case-to-camel-case-conversion.html) + * [snakeCaseMappers](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#snakecasemappers) + * [snake_case to camelCase conversion recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/snake-case-to-camel-case-conversion.md) ##### Examples @@ -488,7 +488,7 @@ class Person extends Model { } ``` -Name of the property used to store a reference to a [uidProp](/api/model/static-properties.html#static-uidprop) +Name of the property used to store a reference to a [uidProp](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-uidprop) NOTE: You cannot use any of the model's properties as `uidRefProp`. For example if your model has a property `ref`, you cannot set `uidRefProp = 'ref'`. @@ -569,7 +569,7 @@ class Person extends Model { ``` Sets the default options for eager loading algorithm. See the possible -fields [here](/api/types/#type-eageroptions). +fields [here](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-eageroptions). Defaults to `{minimize: false, separator: ':', aliases: {}}`. @@ -583,7 +583,7 @@ class Animal extends Model { } ``` -If true, `limit(1)` is added to the query when [first()](/api/query-builder/instance-methods#first) is called. Defaults to `false` for legacy reasons. +If true, `limit(1)` is added to the query when [first()](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/instance-methods#first) is called. Defaults to `false` for legacy reasons. ## `static` QueryBuilder @@ -595,11 +595,11 @@ class Person extends Model { } ``` -[QueryBuilder](/api/query-builder/) subclass to use for all queries created for this model. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) subclass to use for all queries created for this model. -This constructor is used whenever a query builder is created using [query](/api/model/static-methods.html#static-query), [$query](/api/model/instance-methods.html#query), [$relatedQuery](/api/model/instance-methods.html#relatedquery) or any other method that creates a query. You can override this to use your own [QueryBuilder](/api/query-builder/) subclass. +This constructor is used whenever a query builder is created using [query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query), [$query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query), [$relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) or any other method that creates a query. You can override this to use your own [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) subclass. -[Usage example](/recipes/custom-query-builder.html). +[Usage example](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/custom-query-builder.md). ## `static` BelongsToOneRelation @@ -614,7 +614,7 @@ class Person extends Model { } ``` -A relation type that can be used in [relationMappings](/api/model/static-properties.html#static-relationmappings) to create a belongs-to-one relationship. See [this section](/guide/relations.md) for more information about different relation types. +A relation type that can be used in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) to create a belongs-to-one relationship. See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/guide/relations.md) for more information about different relation types. ## `static` HasOneRelation @@ -629,7 +629,7 @@ class Person extends Model { } ``` -A relation type that can be used in [relationMappings](/api/model/static-properties.html#static-relationmappings) to create a has-one relationship. See [this section](/guide/relations.md) for more information about different relation types. +A relation type that can be used in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) to create a has-one relationship. See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/guide/relations.md) for more information about different relation types. ## `static` HasManyRelation @@ -644,7 +644,7 @@ class Person extends Model { } ``` -A relation type that can be used in [relationMappings](/api/model/static-properties.html#static-relationmappings) to create a has-may relationship. See [this section](/guide/relations.md) for more information about different relation types. +A relation type that can be used in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) to create a has-may relationship. See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/guide/relations.md) for more information about different relation types. ## `static` ManyToManyRelation @@ -659,7 +659,7 @@ class Person extends Model { } ``` -A relation type that can be used in [relationMappings](/api/model/static-properties.html#static-relationmappings) to create a many-to-many relationship. See [this section](/guide/relations.md) for more information about different relation types. +A relation type that can be used in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) to create a many-to-many relationship. See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/guide/relations.md) for more information about different relation types. ## `static` HasOneThroughRelation @@ -674,4 +674,4 @@ class Person extends Model { } ``` -A relation type that can be used in [relationMappings](/api/model/static-properties.html#static-relationmappings) to create a has-one-through relationship. See [this section](/guide/relations.md) for more information about different relation types. +A relation type that can be used in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) to create a has-one-through relationship. See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/guide/relations.md) for more information about different relation types. diff --git a/doc/api/objection/README.md b/doc/api/objection/README.md index 9935bea77..0dcea4246 100644 --- a/doc/api/objection/README.md +++ b/doc/api/objection/README.md @@ -17,14 +17,14 @@ The objection module is what you get when you import objection. It has a bunch o const { Model } = require('objection'); ``` -[The model class](/api/model/) +[The model class](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) ## transaction ```js const { transaction } = require('objection'); ``` -[The transaction function](/guide/transactions.html) +[The transaction function](https://github.com/Vincit/objection.js/tree/v1/doc/guide/transactions.md) ## ref @@ -32,9 +32,9 @@ const { transaction } = require('objection'); const { ref } = require('objection'); ``` -Factory function that returns a [ReferenceBuilder](/api/types/#class-referencebuilder) instance, that makes it easier to refer to tables, columns, json attributes etc. [ReferenceBuilder](/api/types/#class-referencebuilder) can also be used to type cast and alias the references. +Factory function that returns a [ReferenceBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-referencebuilder) instance, that makes it easier to refer to tables, columns, json attributes etc. [ReferenceBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-referencebuilder) can also be used to type cast and alias the references. -See [FieldExpression](/api/types/#type-fieldexpression) for more information about how to refer to json fields. +See [FieldExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression) for more information about how to refer to json fields. ##### Examples @@ -62,9 +62,9 @@ await Model.query() const { raw } = require('objection'); ``` -Factory function that returns a [RawBuilder](/api/types/#class-rawbuilder) instance. [RawBuilder](/api/types/#class-rawbuilder) is a wrapper for knex raw method that doesn't depend on knex. Instances of [RawBuilder](/api/types/#class-rawbuilder) are converted to knex raw instances lazily when the query is executed. +Factory function that returns a [RawBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-rawbuilder) instance. [RawBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-rawbuilder) is a wrapper for knex raw method that doesn't depend on knex. Instances of [RawBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-rawbuilder) are converted to knex raw instances lazily when the query is executed. -Also see [the raw query recipe](/recipes/raw-queries.html). +Also see [the raw query recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/raw-queries.md). ##### Examples @@ -131,7 +131,7 @@ await Person const { lit } = require('objection') ``` -Factory function that returns a [LiteralBuilder](/api/types/#class-literalbuilder) instance. [LiteralBuilder](/api/types/#class-literalbuilder) helps build literals of different types. +Factory function that returns a [LiteralBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-literalbuilder) instance. [LiteralBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-literalbuilder) helps build literals of different types. ##### Examples @@ -161,7 +161,7 @@ await Model const { mixin } = require('objection'); ``` -The mixin helper for applying multiple [plugins](/guide/plugins.html). +The mixin helper for applying multiple [plugins](https://github.com/Vincit/objection.js/tree/v1/doc/guide/plugins.md). ##### Examples @@ -185,7 +185,7 @@ class Person extends mixin(Model, [ const { compose } = require('objection'); ``` -The compose helper for applying multiple [plugins](/guide/plugins.html). +The compose helper for applying multiple [plugins](https://github.com/Vincit/objection.js/tree/v1/doc/guide/plugins.md). ##### Examples @@ -211,7 +211,7 @@ class Person extends mixins(Model) { const { snakeCaseMappers } = require('objection'); ``` -Function for adding snake_case to camelCase conversion to objection models. Better documented [here](/recipes/snake-case-to-camel-case-conversion.html). The `snakeCaseMappers` function accepts an options object. The available options are: +Function for adding snake_case to camelCase conversion to objection models. Better documented [here](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/snake-case-to-camel-case-conversion.md). The `snakeCaseMappers` function accepts an options object. The available options are: Option|Type|Description ---------|-------|------------------------ @@ -247,7 +247,7 @@ class Person extends Model { const { knexSnakeCaseMappers } = require('objection'); ``` -Function for adding a snake_case to camelCase conversion to `knex`. Better documented [here](/recipes/snake-case-to-camel-case-conversion.html). The `knexSnakeCaseMappers` function accepts an options object. The available options are: +Function for adding a snake_case to camelCase conversion to `knex`. Better documented [here](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/snake-case-to-camel-case-conversion.md). The `knexSnakeCaseMappers` function accepts an options object. The available options are: Option|Type|Description ---------|-------|------------------------ @@ -316,7 +316,7 @@ const knex = Knex({ const { knexIdentifierMapping } = require('objection'); ``` -Like [knexSnakeCaseMappers](/api/objection/#knexsnakecasemappers), but can be used to make an arbitrary static mapping between column names and property names. In the examples, you would have identifiers `MyId`, `MyProp` and `MyAnotherProp` in the database and you would like to map them into `id`, `prop` and `anotherProp` in the code. +Like [knexSnakeCaseMappers](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#knexsnakecasemappers), but can be used to make an arbitrary static mapping between column names and property names. In the examples, you would have identifiers `MyId`, `MyProp` and `MyAnotherProp` in the database and you would like to map them into `id`, `prop` and `anotherProp` in the code. ##### Examples @@ -406,7 +406,7 @@ const knex = Knex({ const { ValidationError } = require('objection'); ``` -The [ValidationError](/api/types/#class-validationerror) class. +The [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror) class. ## NotFoundError @@ -414,4 +414,4 @@ The [ValidationError](/api/types/#class-validationerror) class. const { NotFoundError } = require('objection'); ``` -The [NotFoundError](/api/types/#class-notfounderror) class. +The [NotFoundError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-notfounderror) class. diff --git a/doc/api/query-builder/README.md b/doc/api/query-builder/README.md index 0db410857..aa38b7b6f 100644 --- a/doc/api/query-builder/README.md +++ b/doc/api/query-builder/README.md @@ -4,8 +4,8 @@ `QueryBuilder` is a wrapper around [knex QueryBuilder](http://knexjs.org#Builder). QueryBuilder has all the methods a knex QueryBuilder has and more. While knex QueryBuilder returns plain JavaScript objects, QueryBuilder returns Model subclass instances. -QueryBuilder is thenable, meaning that it can be used like a promise. You can `await` a query builder, and it will get executed. You can return query builder from a [then](/api/query-builder/other-methods.html#then) method of a promise and it gets chained just like a normal promise would. +QueryBuilder is thenable, meaning that it can be used like a promise. You can `await` a query builder, and it will get executed. You can return query builder from a [then](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#then) method of a promise and it gets chained just like a normal promise would. See also - * [Custom query builder recipe](/recipes/custom-query-builder.html) + * [Custom query builder recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/custom-query-builder.md) diff --git a/doc/api/query-builder/eager-methods.md b/doc/api/query-builder/eager-methods.md index fc9743805..84d151535 100644 --- a/doc/api/query-builder/eager-methods.md +++ b/doc/api/query-builder/eager-methods.md @@ -8,9 +8,9 @@ queryBuilder = queryBuilder.eager(relationExpression, modifiers); Fetch relations eagerly for the result rows. -See the [eager loading](/guide/query-examples.html#eager-loading) section for more examples and [RelationExpression](/api/types/#type-relationexpression) for more info on the relation expression language. +See the [eager loading](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#eager-loading) section for more examples and [RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression) for more info on the relation expression language. -You can choose the way objection performs the eager loading by using [eagerAlgorithm](/api/query-builder/eager-methods.html#eageralgorithm) method on a query builder or by setting the [defaultEagerAlgorithm](/api/model/static-properties.html#static-defaulteageralgorithm) property of a model. The three algorithms currently available are `Model.WhereInEagerAlgorithm` (the default) `Model.JoinEagerAlgorithm` and `Model.NaiveEagerAlgorithm`. All three have their strengths and weaknesses. We will go through the main differences below. You can always see the executed SQL by calling the [debug](/api/query-builder/other-methods.html#debug) method for the query builder. +You can choose the way objection performs the eager loading by using [eagerAlgorithm](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eageralgorithm) method on a query builder or by setting the [defaultEagerAlgorithm](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-defaulteageralgorithm) property of a model. The three algorithms currently available are `Model.WhereInEagerAlgorithm` (the default) `Model.JoinEagerAlgorithm` and `Model.NaiveEagerAlgorithm`. All three have their strengths and weaknesses. We will go through the main differences below. You can always see the executed SQL by calling the [debug](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#debug) method for the query builder. WhereInEagerAlgorithm @@ -44,14 +44,14 @@ cases where performance doesn't matter and when it is the only option to get the Argument|Type|Description --------|----|-------------------- -relationExpression|[RelationExpression](/api/types/#type-relationexpression)|The eager expression -modifiers|Object<string, function([QueryBuilder](/api/query-builder/))>|The modifier functions for the expression +relationExpression|[RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression)|The eager expression +modifiers|Object<string, function([QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/))>|The modifier functions for the expression ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -87,7 +87,7 @@ console.log(people[0].children[0].pets[0].name); cconsole.log(people[0].children[0].movies[0].id); ``` -Reusable modifiers can be defined for a model class using [modifiers](/api/model/static-properties.html#static-modifiers) +Reusable modifiers can be defined for a model class using [modifiers](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modifiers) ```js class Person extends Model { @@ -131,7 +131,7 @@ console.log(people[0].children[0].pets[0].name); console.log(people[0].children[0].movies[0].id); ``` -Filters can also be registered using the [modifyEager](/api/query-builder/other-methods.html#modifyeager) method: +Filters can also be registered using the [modifyEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#modifyeager) method: ```js const people = await Person @@ -188,7 +188,7 @@ console.log(people[0].children[9].children.length); // --> 10 The person has 10 children and they all have 10 children. The query above will return 100 database rows but will generate only three database queries when using `WhereInEagerAlgorithm` and only one query when using `JoinEagerAlgorithm`. -The loading algorithm can be changed using the [eagerAlgorithm](/api/query-builder/eager-methods.html#eageralgorithm) method: +The loading algorithm can be changed using the [eagerAlgorithm](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eageralgorithm) method: ```js const people = await Person @@ -209,7 +209,7 @@ queryBuilder = queryBuilder.eagerAlgorithm(algo); ``` Select the eager loading algorithm for the query. See comparison between -the available algorithms [here](/api/query-builder/eager-methods.html#eager). +the available algorithms [here](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager). ##### Arguments @@ -221,7 +221,7 @@ algo|EagerAlgorithm|The eager loading algorithm to use. One of `Model.JoinEagerA Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -238,19 +238,19 @@ const people = await Person queryBuilder = queryBuilder.eagerOptions(options); ``` -Sets [options](/api/types/#type-eageroptions) for the eager query. +Sets [options](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-eageroptions) for the eager query. ##### Arguments Argument|Type|Description --------|----|-------------------- -options|[EagerOptions](/api/types/#type-eageroptions)|Options to set. +options|[EagerOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-eageroptions)|Options to set. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -293,20 +293,20 @@ queryBuilder ## mergeEager() -Just like [eager](/api/query-builder/eager-methods.html#eager) but instead of replacing query builder's eager expression this method merges the given expression to the existing expression. +Just like [eager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager) but instead of replacing query builder's eager expression this method merges the given expression to the existing expression. ##### Arguments Argument|Type|Description --------|----|-------------------- -relationExpression|[RelationExpression](/api/types/#type-relationexpression)|The eager expression -modifiers|Object<string, function([QueryBuilder](/api/query-builder/))>|The modifier functions for the expression +relationExpression|[RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression)|The eager expression +modifiers|Object<string, function([QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/))>|The modifier functions for the expression ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -365,7 +365,7 @@ builder.eager(eagerObject) Returns the object representation of the current eager expression. -See [this section](/api/types/#relationexpression-object-notation) for more examples and information about the structure of the returned object. +See [this section](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#relationexpression-object-notation) for more examples and information about the structure of the returned object. ##### Return value @@ -402,7 +402,7 @@ queryBuilder = queryBuilder.allowEager(relationExpression); Sets the allowed eager expression. -Any subset of the allowed expression is accepted by [eager](/api/query-builder/eager-methods.html#eager) method. For example setting the allowed expression to `a.b.c` expressions `a`, `a.b` and `a.b.c` are accepted by [eager](/api/query-builder/eager-methods.html#eager) method. Setting any other expression will reject the query and cause the promise error handlers to be called. +Any subset of the allowed expression is accepted by [eager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager) method. For example setting the allowed expression to `a.b.c` expressions `a`, `a.b` and `a.b.c` are accepted by [eager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager) method. Setting any other expression will reject the query and cause the promise error handlers to be called. This method is useful when the eager expression comes from an untrusted source like query parameters of a http request. @@ -410,13 +410,13 @@ This method is useful when the eager expression comes from an untrusted source l Argument|Type|Description --------|----|-------------------- -relationExpression|[RelationExpression](/api/types/#type-relationexpression)|The allowed eager expression +relationExpression|[RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression)|The allowed eager expression ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -429,19 +429,19 @@ Person ## mergeAllowEager() -Just like [allowEager](/api/query-builder/eager-methods.html#alloweager) but instead of replacing query builder's allowEager expression this method merges the given expression to the existing expression. +Just like [allowEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#alloweager) but instead of replacing query builder's allowEager expression this method merges the given expression to the existing expression. ##### Arguments Argument|Type|Description --------|----|-------------------- -relationExpression|[RelationExpression](/api/types/#type-relationexpression)|The allowed eager expression +relationExpression|[RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression)|The allowed eager expression ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -491,14 +491,14 @@ The following query would filter out the children's pets that are <= 10 years ol Argument|Type|Description --------|----|-------------------- -pathExpression|[RelationExpression](/api/types/#type-relationexpression)|Expression that specifies the queries for which to give the filter. -modifier|function([QueryBuilder](/api/query-builder/) | string | string[]|A modifier function, [model modifier](/api/model/static-properties.html#static-modifiers) name or an array of model modifier names. +pathExpression|[RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression)|Expression that specifies the queries for which to give the filter. +modifier|function([QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) | string | string[]|A modifier function, [model modifier](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modifiers) name or an array of model modifier names. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -533,7 +533,7 @@ Person }) ``` -The modifier can also be a [Model modifier](/api/model/static-properties.html#static-modifiers) name, or an array of them: +The modifier can also be a [Model modifier](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modifiers) name, or an array of them: ```js Person @@ -544,4 +544,4 @@ Person ## filterEager() -Alias for [modifyEager](/api/query-builder/other-methods.html#modifyeager). +Alias for [modifyEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#modifyeager). diff --git a/doc/api/query-builder/find-methods.md b/doc/api/query-builder/find-methods.md index bb86f67a3..2e21b6a91 100644 --- a/doc/api/query-builder/find-methods.md +++ b/doc/api/query-builder/find-methods.md @@ -18,7 +18,7 @@ id|any | any[]|The identifier. Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -56,7 +56,7 @@ ids|any[]|A List of identifiers. Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -82,13 +82,13 @@ Shorthand for `where(...whereArgs).first()`. Argument|Type|Description --------|----|-------------------- -whereArgs|...any|Anything the [where](/api/query-builder/find-methods.html#where) method accepts. +whereArgs|...any|Anything the [where](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#where) method accepts. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -126,7 +126,7 @@ alias|string|Table alias for the query. Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -157,7 +157,7 @@ alias|string|The alias. Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -190,7 +190,7 @@ See [knex documentation](http://knexjs.org/#Builder-select) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## forUpdate() @@ -200,7 +200,7 @@ See [knex documentation](http://knexjs.org/#Builder-forUpdate) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## forShare() @@ -210,7 +210,7 @@ See [knex documentation](http://knexjs.org/#Builder-forShare) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## as() @@ -220,7 +220,7 @@ See [knex documentation](http://knexjs.org/#Builder-as) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## columns() @@ -230,7 +230,7 @@ See [knex documentation](http://knexjs.org/#Builder-columns) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## column() @@ -240,7 +240,7 @@ See [knex documentation](http://knexjs.org/#Builder-column) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## from() @@ -250,7 +250,7 @@ See [knex documentation](http://knexjs.org/#Builder-from) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## into() @@ -260,7 +260,7 @@ See [knex documentation](http://knexjs.org/#Builder-into) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## with() @@ -270,7 +270,7 @@ See [knex documentation](http://knexjs.org/#Builder-with) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## withSchema() @@ -280,7 +280,7 @@ See [knex documentation](http://knexjs.org/#Builder-withSchema) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## table() @@ -290,7 +290,7 @@ See [knex documentation](http://knexjs.org/#Builder-table) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## distinct() @@ -300,7 +300,7 @@ See [knex documentation](http://knexjs.org/#Builder-distinct) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## where() @@ -310,7 +310,7 @@ See [knex documentation](http://knexjs.org/#Builder-where) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## andWhere() @@ -321,7 +321,7 @@ See [knex documentation](http://knexjs.org/#Builder-where) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhere() @@ -331,7 +331,7 @@ See [knex documentation](http://knexjs.org/#Builder-where) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereNot() @@ -341,7 +341,7 @@ See [knex documentation](http://knexjs.org/#Builder-where) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereNot() @@ -351,7 +351,7 @@ See [knex documentation](http://knexjs.org/#Builder-where) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereRaw() @@ -361,7 +361,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereRaw) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereWrapped() @@ -371,7 +371,7 @@ See [knex documentation](http://knexjs.org/#Builder-wheres) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## havingWrapped() @@ -381,7 +381,7 @@ See [knex documentation](http://knexjs.org/#Builder-having) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereRaw() @@ -391,7 +391,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereRaw) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereExists() @@ -401,7 +401,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereExists) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereExists() @@ -411,7 +411,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereExists) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereNotExists() @@ -421,7 +421,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereNotExists) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereNotExists() @@ -431,7 +431,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereNotExists) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereIn() @@ -441,7 +441,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereIn) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereIn() @@ -451,7 +451,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereIn) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereNotIn() @@ -461,7 +461,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereNotIn) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereNotIn() @@ -471,7 +471,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereNotIn) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereNull() @@ -481,7 +481,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereNull) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereNull() @@ -491,7 +491,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereNull) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereNotNull() @@ -501,7 +501,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereNotNull) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereNotNull() @@ -511,7 +511,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereNotNull) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereBetween() @@ -521,7 +521,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereBetween) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereNotBetween() @@ -531,7 +531,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereNotBetween) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereBetween() @@ -541,7 +541,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereBetween) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereNotBetween() @@ -551,7 +551,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereNotBetween) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereColumn() @@ -561,7 +561,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereColumn) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## andWhereColumn() @@ -571,7 +571,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereColumn) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereColumn() @@ -581,7 +581,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereColumn) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereNotColumn() @@ -591,7 +591,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereColumn) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## andWhereNotColumn() @@ -601,7 +601,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereColumn) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereNotColumn() @@ -611,7 +611,7 @@ See [knex documentation](http://knexjs.org/#Builder-whereColumn) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## groupBy() @@ -621,7 +621,7 @@ See [knex documentation](http://knexjs.org/#Builder-groupBy) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## groupByRaw() @@ -631,7 +631,7 @@ See [knex documentation](http://knexjs.org/#Builder-groupByRaw) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orderBy() @@ -641,7 +641,7 @@ See [knex documentation](http://knexjs.org/#Builder-orderBy) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orderByRaw() @@ -651,7 +651,7 @@ See [knex documentation](http://knexjs.org/#Builder-orderByRaw) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## union() @@ -661,7 +661,7 @@ See [knex documentation](http://knexjs.org/#Builder-union) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## unionAll() @@ -671,7 +671,7 @@ See [knex documentation](http://knexjs.org/#Builder-unionAll) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## having() @@ -681,7 +681,7 @@ See [knex documentation](http://knexjs.org/#Builder-having) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## havingRaw() @@ -691,7 +691,7 @@ See [knex documentation](http://knexjs.org/#Builder-havingRaw) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orHaving() @@ -701,7 +701,7 @@ See [knex documentation](http://knexjs.org/#Builder-having) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orHavingRaw() @@ -711,7 +711,7 @@ See [knex documentation](http://knexjs.org/#Builder-havingRaw) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## offset() @@ -721,7 +721,7 @@ See [knex documentation](http://knexjs.org/#Builder-offset) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## limit() @@ -731,19 +731,19 @@ See [knex documentation](http://knexjs.org/#Builder-limit) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## count() See [knex documentation](http://knexjs.org/#Builder-count) -Also see the [resultSize](/api/query-builder/other-methods.md#resultsize) method for a cleaner way to just get the number of rows a query would create. +Also see the [resultSize](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#resultsize) method for a cleaner way to just get the number of rows a query would create. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## countDistinct() @@ -753,7 +753,7 @@ See [knex documentation](http://knexjs.org/#Builder-count) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## min() @@ -763,7 +763,7 @@ See [knex documentation](http://knexjs.org/#Builder-min) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## max() @@ -773,7 +773,7 @@ See [knex documentation](http://knexjs.org/#Builder-max) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## sum() @@ -783,7 +783,7 @@ See [knex documentation](http://knexjs.org/#Builder-sum) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## avg() @@ -793,7 +793,7 @@ See [knex documentation](http://knexjs.org/#Builder-avg) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## avgDistinct() @@ -803,7 +803,7 @@ See [knex documentation](http://knexjs.org/#Builder-avg) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## returning() @@ -813,7 +813,7 @@ See [knex documentation](http://knexjs.org/#Builder-returning) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## columnInfo() @@ -823,7 +823,7 @@ See [knex documentation](http://knexjs.org/#Builder-columnInfo) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## whereComposite() @@ -831,13 +831,13 @@ Type|Description queryBuilder = queryBuilder.whereComposite(columns, operator, values); ``` -[where](/api/query-builder/find-methods.html#where) for (possibly) composite keys. +[where](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#where) for (possibly) composite keys. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -857,13 +857,13 @@ builder.whereComposite('id', 1); queryBuilder = queryBuilder.whereInComposite(columns, values); ``` -[whereIn](/api/query-builder/find-methods.html#wherein) for (possibly) composite keys. +[whereIn](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherein) for (possibly) composite keys. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -898,14 +898,14 @@ Where left hand json field reference is a superset of the right hand json value Argument|Type|Description --------|----|-------------------- -fieldExpression|[FieldExpression](/api/types/#type-fieldexpression)|Reference to column / json field, which is tested for being a superset -jsonObjectOrFieldExpression|Object | Array | [FieldExpression](/api/types/#type-fieldexpression)|To which to compare +fieldExpression|[FieldExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression)|Reference to column / json field, which is tested for being a superset +jsonObjectOrFieldExpression|Object | Array | [FieldExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression)|To which to compare ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -958,15 +958,15 @@ Returns only the row `4` which has keys `a` and `b` and `a` != `b`, but it won't ## orWhereJsonSupersetOf() -See [whereJsonSupersetOf](/api/query-builder/find-methods.html#wherejsonsupersetof) +See [whereJsonSupersetOf](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonsupersetof) ## whereJsonNotSupersetOf() -See [whereJsonSupersetOf](/api/query-builder/find-methods.html#wherejsonsupersetof) +See [whereJsonSupersetOf](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonsupersetof) ## orWhereJsonNotSupersetOf() -See [whereJsonSupersetOf](/api/query-builder/find-methods.html#wherejsonsupersetof) +See [whereJsonSupersetOf](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonsupersetof) ## whereJsonSubsetOf() @@ -981,32 +981,32 @@ Where left hand json field reference is a subset of the right hand json value or Object and array are always their own subsets. -See [whereJsonSupersetOf](/api/query-builder/find-methods.html#wherejsonsupersetof) +See [whereJsonSupersetOf](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonsupersetof) ##### Arguments Argument|Type|Description --------|----|-------------------- -fieldExpression|[FieldExpression](/api/types/#type-fieldexpression)|Reference to column / json field, which is tested for being a superset -jsonObjectOrFieldExpression|Object | Array | [FieldExpression](/api/types/#type-fieldexpression)|To which to compare +fieldExpression|[FieldExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression)|Reference to column / json field, which is tested for being a superset +jsonObjectOrFieldExpression|Object | Array | [FieldExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression)|To which to compare ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereJsonSubsetOf() -See [whereJsonSubsetOf](/api/query-builder/find-methods.html#wherejsonsubsetof) +See [whereJsonSubsetOf](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonsubsetof) ## whereJsonNotSubsetOf() -See [whereJsonSubsetOf](/api/query-builder/find-methods.html#wherejsonsubsetof) +See [whereJsonSubsetOf](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonsubsetof) ## orWhereJsonNotSubsetOf() -See [whereJsonSubsetOf](/api/query-builder/find-methods.html#wherejsonsubsetof) +See [whereJsonSubsetOf](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonsubsetof) ## whereJsonIsArray() @@ -1020,25 +1020,25 @@ Where json field reference is an array. Argument|Type|Description --------|----|-------------------- -fieldExpression|[FieldExpression](/api/types/#type-fieldexpression)| +fieldExpression|[FieldExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression)| ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereJsonIsArray() -See [whereJsonIsArray](/api/query-builder/find-methods.html#wherejsonisarray) +See [whereJsonIsArray](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonisarray) ## whereJsonNotArray() -See [whereJsonIsArray](/api/query-builder/find-methods.html#wherejsonisarray) +See [whereJsonIsArray](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonisarray) ## orWhereJsonNotArray() -See [whereJsonIsArray](/api/query-builder/find-methods.html#wherejsonisarray) +See [whereJsonIsArray](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonisarray) ## whereJsonIsObject() @@ -1052,25 +1052,25 @@ Where json field reference is an object. Argument|Type|Description --------|----|-------------------- -fieldExpression|[FieldExpression](/api/types/#type-fieldexpression)| +fieldExpression|[FieldExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression)| ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereJsonIsObject() -See [whereJsonIsObject](/api/query-builder/find-methods.html#wherejsonisobject) +See [whereJsonIsObject](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonisobject) ## whereJsonNotObject() -See [whereJsonIsObject](/api/query-builder/find-methods.html#wherejsonisobject) +See [whereJsonIsObject](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonisobject) ## orWhereJsonNotObject() -See [whereJsonIsObject](/api/query-builder/find-methods.html#wherejsonisobject) +See [whereJsonIsObject](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonisobject) ## whereJsonHasAny() @@ -1088,18 +1088,18 @@ This doesn't work for arrays. If you want to check if an array contains an item, Argument|Type|Description --------|----|-------------------- -fieldExpression|[FieldExpression](/api/types/#type-fieldexpression)| +fieldExpression|[FieldExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression)| keys|string | string[]|Strings that are looked from object or array ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereJsonHasAny() -See [whereJsonHasAny](/api/query-builder/find-methods.html#wherejsonhasany) +See [whereJsonHasAny](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonhasany) ## whereJsonHasAll() @@ -1117,15 +1117,15 @@ This doesn't work for arrays. If you want to check if an array contains an item, Argument|Type|Description --------|----|-------------------- -fieldExpression|[FieldExpression](/api/types/#type-fieldexpression)| +fieldExpression|[FieldExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression)| keys|string | string[]|Strings that are looked from object or array ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## orWhereJsonHasAll() -See [whereJsonHasAll](/api/query-builder/find-methods.html#wherejsonhasall) +See [whereJsonHasAll](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonhasall) diff --git a/doc/api/query-builder/join-methods.md b/doc/api/query-builder/join-methods.md index 0d2adc5c9..55d22e551 100644 --- a/doc/api/query-builder/join-methods.md +++ b/doc/api/query-builder/join-methods.md @@ -12,14 +12,14 @@ Joins a set of relations described by `relationExpression`. See the examples for Argument|Type|Description --------|----|-------------------- -relationExpression|[RelationExpression](/api/types/#type-relationexpression)|An expression describing which relations to join. +relationExpression|[RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression)|An expression describing which relations to join. opt|object|Optional options. See the examples. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -51,7 +51,7 @@ await Person .where('parent.name', 'Arnold'); ``` -You can also use the [object notation](/api/types/#relationexpression-object-notation) +You can also use the [object notation](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#relationexpression-object-notation) ```js await Person @@ -101,31 +101,31 @@ await Person ## innerJoinRelation() -Alias for [joinRelation](/api/query-builder/join-methods.html#joinrelation). +Alias for [joinRelation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/join-methods.md#joinrelation). ## outerJoinRelation() -Outer join version of the [joinRelation](/api/query-builder/join-methods.html#joinrelation) method. +Outer join version of the [joinRelation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/join-methods.md#joinrelation) method. ## leftJoinRelation() -Left join version of the [joinRelation](/api/query-builder/join-methods.html#joinrelation) method. +Left join version of the [joinRelation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/join-methods.md#joinrelation) method. ## leftOuterJoinRelation() -Left outer join version of the [joinRelation](/api/query-builder/join-methods.html#joinrelation) method. +Left outer join version of the [joinRelation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/join-methods.md#joinrelation) method. ## rightJoinRelation() -Right join version of the [joinRelation](/api/query-builder/join-methods.html#joinrelation) method. +Right join version of the [joinRelation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/join-methods.md#joinrelation) method. ## rightOuterJoinRelation() -Left outer join version of the [joinRelation](/api/query-builder/join-methods.html#joinrelation) method. +Left outer join version of the [joinRelation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/join-methods.md#joinrelation) method. ## fullOuterJoinRelation() -Full outer join version of the [joinRelation](/api/query-builder/join-methods.html#joinrelation) method. +Full outer join version of the [joinRelation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/join-methods.md#joinrelation) method. ## join() @@ -135,7 +135,7 @@ See [knex documentation](http://knexjs.org/#Builder-join) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## joinRaw() @@ -145,7 +145,7 @@ See [knex documentation](http://knexjs.org/#Builder-joinRaw) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## innerJoin() @@ -155,7 +155,7 @@ See [knex documentation](http://knexjs.org/#Builder-innerJoin) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## leftJoin() @@ -165,7 +165,7 @@ See [knex documentation](http://knexjs.org/#Builder-leftJoin) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## leftOuterJoin() @@ -175,7 +175,7 @@ See [knex documentation](http://knexjs.org/#Builder-leftOuterJoin) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## rightJoin() @@ -185,7 +185,7 @@ See [knex documentation](http://knexjs.org/#Builder-rightJoin) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## rightOuterJoin() @@ -195,7 +195,7 @@ See [knex documentation](http://knexjs.org/#Builder-rightOuterJoin) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## outerJoin() @@ -205,7 +205,7 @@ See [knex documentation](http://knexjs.org/#Builder-outerJoin) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## fullOuterJoin() @@ -215,7 +215,7 @@ See [knex documentation](http://knexjs.org/#Builder-fullOuterJoin) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## crossJoin() @@ -225,4 +225,4 @@ See [knex documentation](http://knexjs.org/#Builder-crossJoin) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. diff --git a/doc/api/query-builder/mutate-methods.md b/doc/api/query-builder/mutate-methods.md index 04f20f7c1..fa5ae0cbf 100644 --- a/doc/api/query-builder/mutate-methods.md +++ b/doc/api/query-builder/mutate-methods.md @@ -8,33 +8,33 @@ queryBuilder = queryBuilder.insert(modelsOrObjects); Creates an insert query. -The inserted objects are validated against the model's [jsonSchema](/api/model/static-properties.html#static-jsonschema). If validation fails -the Promise is rejected with a [ValidationError](/api/types/#class-validationerror). +The inserted objects are validated against the model's [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema). If validation fails +the Promise is rejected with a [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror). NOTE: The return value of the insert query _only_ contains the properties given to the insert method plus the identifier. This is because we don't make an additional fetch query after -the insert. Using postgres you can chain [returning('*')](/api/query-builder/find-methods.html#returning) to the query to get all -properties - see [this recipe](/recipes/returning-tricks.html) for some examples. If you use +the insert. Using postgres you can chain [returning('*')](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#returning) to the query to get all +properties - see [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/returning-tricks.md) for some examples. If you use `returning(['only', 'some', 'props'])` note that the result object will still contain the input properies -__plus__ the properties listed in `returning`. On other databases you can use the [insertAndFetch](/api/query-builder/mutate-methods.html#insertandfetch) method. +__plus__ the properties listed in `returning`. On other databases you can use the [insertAndFetch](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertandfetch) method. Batch inserts only work on Postgres because Postgres is the only database engine that returns the identifiers of _all_ inserted rows. knex supports batch inserts on other databases also, but you only get the id of the first (or last) inserted object as a result. If you need batch insert on other databases you can use knex directly -through [knexQuery](/api/model/static-methods.html#static-knexquery). +through [knexQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-knexquery). ##### Arguments Argument|Type|Description --------|----|-------------------- -modelsOrObjects|Object | [Model](/api/model/) | Object[] | [Model](/api/model/)[]|Objects to insert +modelsOrObjects|Object | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) | Object[] | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)[]|Objects to insert ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -73,9 +73,9 @@ await Person }); ``` -Fields marked as `extras` for many-to-many relations in [relationMappings](/api/model/static-properties.html#static-relationmappings) are automatically +Fields marked as `extras` for many-to-many relations in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) are automatically written to the join table instead of the target table. The `someExtra` field in the following example is written -to the join table if the `extra` array of the relation mapping contains the string `'someExtra'`. See [this recipe](/recipes/extra-properties.html) for more info. +to the join table if the `extra` array of the relation mapping contains the string `'someExtra'`. See [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/extra-properties.md) for more info. ```js const jennifer = await someMovie @@ -95,21 +95,21 @@ console.log(jennifer.someExtra); queryBuilder = queryBuilder.insertAndFetch(modelsOrObjects); ``` -Just like [insert](/api/query-builder/mutate-methods.html#insert) but also fetches the item afterwards. +Just like [insert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insert) but also fetches the item afterwards. -Note that on postgresql you can just chain [returning('*')](/api/query-builder/find-methods.html#returning) to the normal insert query to get the same result without an additional query. See [this recipe](/recipes/returning-tricks.html) for some examples. +Note that on postgresql you can just chain [returning('*')](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#returning) to the normal insert query to get the same result without an additional query. See [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/returning-tricks.md) for some examples. ##### Arguments Argument|Type|Description --------|----|-------------------- -modelsOrObjects|Object | [Model](/api/model/) | Object[] | [Model](/api/model/)[]|Objects to insert +modelsOrObjects|Object | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) | Object[] | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)[]|Objects to insert ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## insertGraph() @@ -117,20 +117,20 @@ Type|Description queryBuilder = queryBuilder.insertGraph(graph, options); ``` -See the [section about graph inserts](/guide/query-examples.html#graph-inserts). +See the [section about graph inserts](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-inserts). ##### Arguments Argument|Type|Description --------|----|-------------------- -graph|Object | [Model](/api/model/) | Object[] | [Model](/api/model/)[]|Objects to insert -options|[InsertGraphOptions](/api/types/#type-insertgraphoptions)|Optional options. +graph|Object | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) | Object[] | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)[]|Objects to insert +options|[InsertGraphOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-insertgraphoptions)|Optional options. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## allowInsert() @@ -138,23 +138,23 @@ Type|Description queryBuilder = queryBuilder.allowInsert(relationExpression); ``` -Sets the allowed tree of relations to insert using [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) method. +Sets the allowed tree of relations to insert using [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) method. -If the model tree given to the [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) method isn't a subtree of the given expression, the query is rejected. +If the model tree given to the [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) method isn't a subtree of the given expression, the query is rejected. -See methods [eager](/api/query-builder/eager-methods.html#eager), [allowEager](/api/query-builder/eager-methods.html#alloweager), [RelationExpression](/api/types/#type-relationexpression) and the guide section about [eager loading](/guide/query-examples.html#eager-loading) for more information on relation expressions. +See methods [eager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager), [allowEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#alloweager), [RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression) and the guide section about [eager loading](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#eager-loading) for more information on relation expressions. ##### Arguments Argument|Type|Description --------|----|-------------------- -relationExpression|[RelationExpression](/api/types/#type-relationexpression)|The allowed eager expression +relationExpression|[RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression)|The allowed eager expression ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -179,7 +179,7 @@ const insertedPerson = await Person ## insertGraphAndFetch() -Exactly like [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) but also fetches the graph from the db after insert. Note that on postgres, you can simply chain [returning('*')](/api/query-builder/find-methods.html#returning) to the normal `insertGraph` query to get the same result without additional queries. +Exactly like [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) but also fetches the graph from the db after insert. Note that on postgres, you can simply chain [returning('*')](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#returning) to the normal `insertGraph` query to get the same result without additional queries. ## insertWithRelated() @@ -187,7 +187,7 @@ Exactly like [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) b Deprecated! Will be removed in version 2.0. ::: -Alias for [insertGraph](/api/query-builder/mutate-methods.html#insertgraph). +Alias for [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph). ## insertWithRelatedAndFetch() @@ -195,7 +195,7 @@ Alias for [insertGraph](/api/query-builder/mutate-methods.html#insertgraph). Deprecated! Will be removed in version 2.0. ::: -Alias for [insertGraphAndFetch](/api/query-builder/mutate-methods.html#insertgraphandfetch). +Alias for [insertGraphAndFetch](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraphandfetch). ## patch() @@ -205,31 +205,31 @@ queryBuilder = queryBuilder.patch(modelOrObject); Creates a patch query. -The patch object is validated against the model's [jsonSchema](/api/model/static-properties.html#static-jsonschema) (if one is defined) _but_ the `required` property of the [jsonSchema](/api/model/static-properties.html#static-jsonschema) is ignored. This way the properties in the patch object are still validated but an error isn't thrown if the patch object doesn't contain all required properties. +The patch object is validated against the model's [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema) (if one is defined) _but_ the `required` property of the [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema) is ignored. This way the properties in the patch object are still validated but an error isn't thrown if the patch object doesn't contain all required properties. -If validation fails the Promise is rejected with a [ValidationError](/api/types/#class-validationerror). +If validation fails the Promise is rejected with a [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror). -The return value of the query will be the number of affected rows. If you want to update a single row and retrieve the updated row as a result, you may want to use the [patchAndFetchById](/api/query-builder/mutate-methods.html#patchandfetchbyid) method or *take a look at [this recipe](/recipes/returning-tricks.html) if you're using Postgres*. +The return value of the query will be the number of affected rows. If you want to update a single row and retrieve the updated row as a result, you may want to use the [patchAndFetchById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patchandfetchbyid) method or *take a look at [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/returning-tricks.md) if you're using Postgres*. ::: tip -This generates an SQL `update` query. While there's also the [update](/api/query-builder/mutate-methods.html#update) method, `patch` is what you want to use most of the time for updates. Read both methods' documentation carefully. If unsure or hate reading, use `patch` to update stuff :smile: +This generates an SQL `update` query. While there's also the [update](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#update) method, `patch` is what you want to use most of the time for updates. Read both methods' documentation carefully. If unsure or hate reading, use `patch` to update stuff :smile: ::: ::: warning -[raw](/api/objection/#raw), [lit](/api/objection/#lit), subqueries and other "query properties" in the patch object are not validated. Also fields specified using [FieldExpressions](/api/types/#type-fieldexpression) are not validated. +[raw](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#raw), [lit](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#lit), subqueries and other "query properties" in the patch object are not validated. Also fields specified using [FieldExpressions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression) are not validated. ::: ##### Arguments Argument|Type|Description --------|----|-------------------- -modelOrObject|Object | [Model](/api/model/)|The patch object +modelOrObject|Object | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The patch object ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -262,7 +262,7 @@ const numberOfAffectedRows = await Person .where('age', '<', 50) ``` -You can also give raw expressions, subqueries and `ref()` as values and [FieldExpressions](/api/types/#type-fieldexpression) as keys. Note that none of these are validated. Objection cannot know what their values will be at the time the validation is done. +You can also give raw expressions, subqueries and `ref()` as values and [FieldExpressions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression) as keys. Note that none of these are validated. Objection cannot know what their values will be at the time the validation is done. ```js const { ref, raw } = require('objection'); @@ -287,20 +287,20 @@ await Person queryBuilder = queryBuilder.patchAndFetchById(id, modelOrObject); ``` -Just like [patch](/api/query-builder/mutate-methods.html#patch) for a single item, but also fetches the updated row from the database afterwards. +Just like [patch](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patch) for a single item, but also fetches the updated row from the database afterwards. ##### Arguments Argument|Type|Description --------|----|-------------------- id|any|Identifier of the item to update. Can be a composite key. -modelOrObject|Object | [Model](/api/model/)|The patch object +modelOrObject|Object | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The patch object ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -318,19 +318,19 @@ console.log(updatedPerson.firstName); queryBuilder = queryBuilder.patchAndFetchById(id, modelOrObject); ``` -Just like [patchAndFetchById](/api/query-builder/mutate-methods.html#patchandfetchbyid) but can be used in an instance [$query](/api/model/instance-methods.html#query) without the need to specify the id. +Just like [patchAndFetchById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patchandfetchbyid) but can be used in an instance [$query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query) without the need to specify the id. ##### Arguments Argument|Type|Description --------|----|-------------------- -modelOrObject|Object | [Model](/api/model/)|The patch object +modelOrObject|Object | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The patch object ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -349,23 +349,23 @@ queryBuilder = queryBuilder.update(modelOrObject); Creates an update query. -The update object is validated against the model's [jsonSchema](/api/model/static-properties.html#static-jsonschema). If validation fails the Promise is rejected with a [ValidationError](/api/types/#class-validationerror). +The update object is validated against the model's [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema). If validation fails the Promise is rejected with a [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror). -Use `update` if you update the whole row with all its columns. Otherwise, using the [patch](/api/query-builder/mutate-methods.html#patch) method is recommended. When `update` method is used, the validation respects the schema's `required` properties and throws a [ValidationError](/api/types/#class-validationerror) if any of them are missing. [patch](/api/query-builder/mutate-methods.html#patch) ignores the `required` properties and only validates the ones that are found. +Use `update` if you update the whole row with all its columns. Otherwise, using the [patch](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patch) method is recommended. When `update` method is used, the validation respects the schema's `required` properties and throws a [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror) if any of them are missing. [patch](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patch) ignores the `required` properties and only validates the ones that are found. -The return value of the query will be the number of affected rows. If you want to update a single row and retrieve the updated row as a result, you may want to use the [updateAndFetchById](/api/query-builder/mutate-methods.html#updateandfetchbyid) method or *take a look at [this recipe](/recipes/returning-tricks.html) if you're using Postgres*. +The return value of the query will be the number of affected rows. If you want to update a single row and retrieve the updated row as a result, you may want to use the [updateAndFetchById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#updateandfetchbyid) method or *take a look at [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/returning-tricks.md) if you're using Postgres*. ##### Arguments Argument|Type|Description --------|----|-------------------- -modelOrObject|Object | [Model](/api/model/)|The update object +modelOrObject|Object | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The update object ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -410,20 +410,20 @@ await Person queryBuilder = queryBuilder.updateAndFetchById(id, modelOrObject); ``` -Just like [update](/api/query-builder/mutate-methods.html#update) for a single item, but also fetches the updated row from the database afterwards. +Just like [update](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#update) for a single item, but also fetches the updated row from the database afterwards. ##### Arguments Argument|Type|Description --------|----|-------------------- id|any|Identifier of the item to update. Can be a composite key. -modelOrObject|Object | [Model](/api/model/)|The update object +modelOrObject|Object | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The update object ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -441,19 +441,19 @@ console.log(updatedPerson.firstName); queryBuilder = queryBuilder.updateAndFetchById(id, modelOrObject); ``` -Just like [updateAndFetchById](/api/query-builder/mutate-methods.html#updateandfetchbyid) but can be used in an instance [$query](/api/model/instance-methods.html#query) without the need to specify the id. +Just like [updateAndFetchById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#updateandfetchbyid) but can be used in an instance [$query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query) without the need to specify the id. ##### Arguments Argument|Type|Description --------|----|-------------------- -modelOrObject|Object | [Model](/api/model/)|The update object +modelOrObject|Object | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The update object ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -470,28 +470,28 @@ console.log(updatedJennifer.firstName); queryBuilder = queryBuilder.upsertGraph(graph, options); ``` -See the [section about graph upserts](/guide/query-examples.html#graph-upserts) +See the [section about graph upserts](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts) ##### Arguments Argument|Type|Description --------|----|-------------------- -graph|Object | [Model](/api/model/) | Object[] | [Model](/api/model/)[]|Objects to upsert -options|[UpsertGraphOptions](/api/types/#type-upsertgraphoptions)|Optional options. +graph|Object | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) | Object[] | [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)[]|Objects to upsert +options|[UpsertGraphOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-upsertgraphoptions)|Optional options. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## allowUpsert() -Just like [allowInsert](/api/query-builder/mutate-methods.html#allowinsert) but this one works with [upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph). +Just like [allowInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#allowinsert) but this one works with [upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph). ## upsertGraphAndFetch() -Exactly like [upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph) but also fetches the graph from the db after the upsert operation. +Exactly like [upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph) but also fetches the graph from the db after the upsert operation. ## delete() @@ -502,15 +502,15 @@ queryBuilder = queryBuilder.delete(); Creates a delete query. The return value of the query will be the number of deleted rows. if you're using Postgres -and want to get the deleted rows, *take a look at [this recipe](/recipes/returning-tricks.html)*. +and want to get the deleted rows, *take a look at [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/returning-tricks.md)*. -Also see [deleteById](/api/query-builder/mutate-methods.html#deletebyid). +Also see [deleteById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#deletebyid). ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -547,7 +547,7 @@ await Person ); ``` -Delete can of course be used with [$relatedQuery](/api/model/instance-methods.html#relatedquery) and [$query](/api/model/instance-methods.html#query) too. +Delete can of course be used with [$relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) and [$query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query) too. ```js const person = await Person.query().findById(personId); @@ -572,7 +572,7 @@ queryBuilder = queryBuilder.deleteById(id); Deletes an item by id. -The return value of the query will be the number of deleted rows. if you're using Postgres and want to get the deleted rows, *take a look at [this recipe](/recipes/returning-tricks.html)*. +The return value of the query will be the number of deleted rows. if you're using Postgres and want to get the deleted rows, *take a look at [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/returning-tricks.md)*. ##### Arguments @@ -584,7 +584,7 @@ id|any | any[]|The id. Array for composite keys. This method does Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -629,7 +629,7 @@ ids|number | string | Array | Objec Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -662,7 +662,7 @@ const numRelatedRows = await person console.log(`${numRelatedRows} rows were related`); ``` -Fields marked as [extras](/api/types/#type-relationthrough) for many-to-many relations in [relationMappings](/api/model/static-properties.html#static-relationmappings) are automatically written to the join table. The `someExtra` field in the following example is written to the join table if the `extra` array of the relation mapping contains the string `'someExtra'`. +Fields marked as [extras](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationthrough) for many-to-many relations in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) are automatically written to the join table. The `someExtra` field in the following example is written to the join table if the `extra` array of the relation mapping contains the string `'someExtra'`. ```js const numRelatedRows = await someMovie @@ -694,7 +694,7 @@ Use `unrelate` like `delete` and filter the rows using the returned query builde Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -720,7 +720,7 @@ See [knex documentation](http://knexjs.org/#Builder-increment) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## decrement() @@ -730,7 +730,7 @@ See [knex documentation](http://knexjs.org/#Builder-decrement) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## truncate() @@ -740,4 +740,4 @@ See [knex documentation](http://knexjs.org/#Builder-truncate) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. diff --git a/doc/api/query-builder/other-methods.md b/doc/api/query-builder/other-methods.md index bfbebc335..c81ad9bcd 100644 --- a/doc/api/query-builder/other-methods.md +++ b/doc/api/query-builder/other-methods.md @@ -8,7 +8,7 @@ See [knex documentation](http://knexjs.org/#Builder-debug) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## context() @@ -20,15 +20,15 @@ Sets/gets the query context. Some query builder methods create more than one query. The query context is an object that is shared with all queries started by a query builder. -The context is also passed to [$beforeInsert](/api/model/instance-methods.html#beforeinsert), [$afterInsert](/api/model/instance-methods.html#afterinsert), [$beforeUpdate](/api/model/instance-methods.html#beforeupdate), [$afterUpdate](/api/model/instance-methods.html#afterupdate), [$beforeDelete](/api/model/instance-methods.html#beforedelete), [$afterDelete](/api/model/instance-methods.html#afterdelete) and [$afterGet](/api/model/instance-methods.html#afterget) calls that the query creates. +The context is also passed to [$beforeInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforeinsert), [$afterInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#afterinsert), [$beforeUpdate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforeupdate), [$afterUpdate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#afterupdate), [$beforeDelete](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforedelete), [$afterDelete](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#afterdelete) and [$afterGet](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#afterget) calls that the query creates. -In addition to properties added using this method (and [mergeContext](/api/query-builder/other-methods.html#mergecontext)) the query context object always has a `transaction` property that holds the active transaction. If there is no active transaction the `transaction` property contains the normal knex instance. In both cases the value can be passed anywhere where a transaction object can be passed so you never need to check for the existence of the `transaction` property. +In addition to properties added using this method (and [mergeContext](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#mergecontext)) the query context object always has a `transaction` property that holds the active transaction. If there is no active transaction the `transaction` property contains the normal knex instance. In both cases the value can be passed anywhere where a transaction object can be passed so you never need to check for the existence of the `transaction` property. -See the methods [runBefore](/api/query-builder/other-methods.html#runbefore), [onBuild](/api/query-builder/other-methods.html#onbuild) and [runAfter](/api/query-builder/other-methods.html#runafter) +See the methods [runBefore](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#runbefore), [onBuild](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#onbuild) and [runAfter](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#runafter) for more information about the hooks. ::: tip -Most of the time, you should be using [mergeContext](/api/query-builder/other-methods.html#mergecontext) instead of this method. This method replaces the whole context, while `mergeContext` merges the values with the current ones. +Most of the time, you should be using [mergeContext](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#mergecontext) instead of this method. This method replaces the whole context, while `mergeContext` merges the values with the current ones. ::: ##### Arguments @@ -41,7 +41,7 @@ queryContext|Object|The query context object Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -96,7 +96,7 @@ queryBuilder = queryBuilder.mergeContext(queryContext); Merges values into the query context. -This method is like [context](/api/query-builder/other-methods.html#context) but instead of replacing the whole context this method merges the objects. +This method is like [context](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context) but instead of replacing the whole context this method merges the objects. ##### Arguments @@ -108,7 +108,7 @@ queryContext|Object|The object to merge into the query context. Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## tableNameFor() @@ -116,7 +116,7 @@ Type|Description const tableName = queryBuilder.tableNameFor(modelClass); ``` -Returns the table name for a given model class in the query. Usually the table name can be fetched through `Model.tableName` but if the source table has been changed for example using the [QueryBuilder#table](/api/query-builder/find-methods.html#table) method `tableNameFor` will return the correct value. +Returns the table name for a given model class in the query. Usually the table name can be fetched through `Model.tableName` but if the source table has been changed for example using the [QueryBuilder#table](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#table) method `tableNameFor` will return the correct value. ##### Arguments @@ -170,7 +170,7 @@ reson| |The rejection reason Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## resolve() @@ -190,7 +190,7 @@ value| |The resolve value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## isExecutable() @@ -202,7 +202,7 @@ Returns false if this query will never be executed. This may be true in multiple cases: -1. The query is explicitly resolved or rejected using the [resolve](/api/query-builder/other-methods.html#resolve) or [reject](/api/query-builder/other-methods.html#reject) methods. +1. The query is explicitly resolved or rejected using the [resolve](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#resolve) or [reject](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#reject) methods. 2. The query starts a different query when it is executed. ##### Return value @@ -397,7 +397,7 @@ selector|string | regexp|A name or regular expression to match al Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -417,13 +417,13 @@ Registers a function to be called before just the database query when the builde Argument|Type|Description --------|----|-------------------- -runBefore|function(result, [QueryBuilder](/api/query-builder/))|The function to be executed. This function can be async. Note that it needs to return the result used for further processing in the chain of calls. +runBefore|function(result, [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/))|The function to be executed. This function can be async. Note that it needs to return the result used for further processing in the chain of calls. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -456,7 +456,7 @@ await query; queryBuilder = queryBuilder.onBuild(onBuild); ``` -Functions registered with this method are called each time the query is built into an SQL string. This method is ran after [runBefore](/api/query-builder/other-methods.html#runbefore) methods but before [runAfter](/api/query-builder/other-methods.html#runafter) methods. +Functions registered with this method are called each time the query is built into an SQL string. This method is ran after [runBefore](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#runbefore) methods but before [runAfter](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#runafter) methods. If you need to modify the SQL query at query build time, this is the place to do it. You shouldn't modify the query in any of the `run` methods. @@ -466,13 +466,13 @@ Unlike the `run` methods (`runAfter`, `runBefore` etc.) these must be synchronou Argument|Type|Description --------|----|-------------------- -onBuild|function([QueryBuilder](/api/query-builder/))|The **synchronous** function to be executed. +onBuild|function([QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/))|The **synchronous** function to be executed. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Eamples @@ -494,7 +494,7 @@ query queryBuilder = queryBuilder.onBuildKnex(onBuildKnex); ``` -Functions registered with this method are called each time the query is built into an SQL string. This method is ran after [onBuild](/api/query-builder/other-methods.html#onbuild) methods but before [runAfter](/api/query-builder/other-methods.html#runafter) methods. +Functions registered with this method are called each time the query is built into an SQL string. This method is ran after [onBuild](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#onbuild) methods but before [runAfter](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#runafter) methods. If you need to modify the SQL query at query build time, this is the place to do it in addition to `onBuild`. The only difference between `onBuildKnex` and `onBuild` is that in `onBuild` you can modify the objection's query builder. In `onBuildKnex` the objection builder has been compiled into a knex query builder and any modifications to the objection builder will be ignored. @@ -508,13 +508,13 @@ You should never call any query building (or any other mutating) method on the ` Argument|Type|Description --------|----|-------------------- -onBuildKnex|function(`KnexQueryBuilder`, [QueryBuilder](/api/query-builder/))|The function to be executed. +onBuildKnex|function(`KnexQueryBuilder`, [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/))|The function to be executed. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -535,19 +535,19 @@ queryBuilder = queryBuilder.runAfter(runAfter); Registers a function to be called when the builder is executed. -These functions are executed as the last thing before any promise handlers registered using the [then](/api/query-builder/other-methods.html#then) method. Multiple functions can be chained like [then](/api/query-builder/other-methods.html#then) methods of a promise. +These functions are executed as the last thing before any promise handlers registered using the [then](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#then) method. Multiple functions can be chained like [then](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#then) methods of a promise. ##### Arguments Argument|Type|Description --------|----|-------------------- -runAfter|function(result, [QueryBuilder](/api/query-builder/))|The function to be executed. This function can be async. Note that it needs to return the result used for further processing in the chain of calls. +runAfter|function(result, [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/))|The function to be executed. This function can be async. Note that it needs to return the result used for further processing in the chain of calls. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -578,13 +578,13 @@ Registers an error handler. Just like `catch` but doesn't execute the query. Argument|Type|Description --------|----|-------------------- -onError|function(Error, [QueryBuilder](/api/query-builder/))|The function to be executed on error. +onError|function(Error, [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/))|The function to be executed on error. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -618,13 +618,13 @@ Sets the model class of the result rows. Type|Description ----|----------------------------- -[ModelClass](/api/model/)|The model class of the result rows. +[ModelClass](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The model class of the result rows. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ##### Examples @@ -667,7 +667,7 @@ Gets the Model subclass this builder is bound to. Type|Description ----|----------------------------- -[Model](/api/model/)|The Model subclass this builder is bound to +[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The Model subclass this builder is bound to ## toString() @@ -721,7 +721,7 @@ For example the following query will return all `Person` rows if `req.query.firs Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining ##### Examples @@ -750,7 +750,7 @@ transaction|object|A transaction object Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining ## clone() @@ -762,7 +762,7 @@ Create a clone of this builder. Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|Clone of the query builder +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|Clone of the query builder ## execute() @@ -947,7 +947,7 @@ Type|Description const promise = queryBuilder.resultSize(); ``` -Returns the amount of rows the current query would produce without [limit](/api/query-builder/find-methods.html#limit) and [offset](/api/query-builder/find-methods.html#offset) applied. Note that this executes a copy of the query and returns a Promise. +Returns the amount of rows the current query would produce without [limit](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#limit) and [offset](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#offset) applied. Note that this executes a copy of the query and returns a Promise. This method is often more convenient than `count` which returns an array of objects instead a single number. @@ -1003,7 +1003,7 @@ pageSize|number|The page size Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining ## range() @@ -1030,7 +1030,7 @@ end|number|The index of the last result (inclusive) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining ##### Examples @@ -1075,7 +1075,7 @@ propertyName|string|The name of the property to pluck Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining ##### Examples @@ -1096,15 +1096,15 @@ queryBuilder = queryBuilder.first(); If the result is an array, selects the first item. -NOTE: This doesn't add `limit 1` to the query by default. You can override the [Model.useLimitInFirst](/api/model/static-properties.html#static-uselimitinfirst) property to change this behaviour. +NOTE: This doesn't add `limit 1` to the query by default. You can override the [Model.useLimitInFirst](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-uselimitinfirst) property to change this behaviour. -Also see [findById](/api/query-builder/find-methods.html#findbyid) and [findOne](/api/query-builder/find-methods.html#findone) shorthand methods. +Also see [findById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#findbyid) and [findOne](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#findone) shorthand methods. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining ##### Examples @@ -1122,15 +1122,15 @@ console.log(firstPerson.age); queryBuilder = queryBuilder.throwIfNotFound(); ``` -Causes a [Model.NotFoundError](/api/types/#class-notfounderror) to be thrown if the query result is empty. +Causes a [Model.NotFoundError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-notfounderror) to be thrown if the query result is empty. -You can replace `Model.NotFoundError` with your own error by implementing the static [Model.createNotFoundError(ctx)](/api/model/static-methods.html#static-createnotfounderror) method. +You can replace `Model.NotFoundError` with your own error by implementing the static [Model.createNotFoundError(ctx)](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-createnotfounderror) method. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining ##### Examples @@ -1161,14 +1161,14 @@ The optional first parameter can be a constructor. If given, the traverser funct Argument|Type|Description --------|----|-------------------- -modelClass|[Model](/api/model/)|The optional model class filter. If given, the traverser function is only called for models of this class. -traverser|function([Model](/api/model/), [Model](/api/model/), string)|The traverser function that is called for each model. The first argument is the model itself. If the model is in a relation of some other model the second argument is the parent model and the third argument is the name of the relation. +modelClass|[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The optional model class filter. If given, the traverser function is only called for models of this class. +traverser|function([Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/), [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/), string)|The traverser function that is called for each model. The first argument is the model itself. If the model is in a relation of some other model the second argument is the parent model and the third argument is the name of the relation. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining ##### Examples @@ -1213,14 +1213,14 @@ instances and `id` and `name` properties of all `Animal` instances. Argument|Type|Description --------|----|-------------------- -modelClass|[Model](/api/model/)|The optional model class filter +modelClass|[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The optional model class filter properties|string[]|The properties to pick ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining ##### Examples @@ -1260,14 +1260,14 @@ and `species` properties of all `Animal` instances. Argument|Type|Description --------|----|-------------------- -modelClass|[Model](/api/model/)|The optional model class filter +modelClass|[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)|The optional model class filter properties|string[]|The properties to omit ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining ##### Examples @@ -1298,7 +1298,7 @@ See [knex documentation](http://knexjs.org/#Builder-timeout) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## connection() @@ -1309,11 +1309,11 @@ See [knex documentation](http://knexjs.org/#Builder-connection) Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## modify() -Works like `knex`'s [modify](http://knexjs.org/#Builder-modify) function but in addition you can specify model [modifier](/api/model/static-properties.html#static-modifiers) by providing modifier names. +Works like `knex`'s [modify](http://knexjs.org/#Builder-modify) function but in addition you can specify model [modifier](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modifiers) by providing modifier names. See [knex documentation](http://knexjs.org/#Builder-modify) @@ -1321,14 +1321,14 @@ See [knex documentation](http://knexjs.org/#Builder-modify) Argument|Type|Description --------|----|-------------------- -modifier|function([QueryBuilder](/api/query-builder/)) | string | string[]|The modify callback function, receiving the builder as its first argument, followed by the optional arguments. If a string is provided, the corresponding [modifier](/api/model/static-properties.html#static-modifiers) is executed instead. +modifier|function([QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)) | string | string[]|The modify callback function, receiving the builder as its first argument, followed by the optional arguments. If a string is provided, the corresponding [modifier](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modifiers) is executed instead. *arguments|...any|The optional arguments passed to the modify function ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## applyModifier() @@ -1338,15 +1338,15 @@ Applies modifiers to the query builder. Argument|Type|Description --------|----|-------------------- -modifier|string|The name of the modifier, as found in [modifier](/api/model/static-properties.html#static-modifiers). +modifier|string|The name of the modifier, as found in [modifier](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modifiers). *arguments| |When providing multiple arguments, all provided modifiers will be applied. ##### Return value Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|`this` query builder for chaining. +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|`this` query builder for chaining. ## applyFilter() -An alias for [applyModifier](/api/query-builder/other-methods.html#applymodifier) +An alias for [applyModifier](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#applymodifier) diff --git a/doc/api/query-builder/static-methods.md b/doc/api/query-builder/static-methods.md index 035547353..50567d662 100644 --- a/doc/api/query-builder/static-methods.md +++ b/doc/api/query-builder/static-methods.md @@ -6,7 +6,7 @@ const builder = QueryBuilder.forClass(modelClass); ``` -Create QueryBuilder for a Model subclass. You rarely need to call this. Query builders are created using the [Model.query()](/api/model/static-methods.html#query) and other query methods. +Create QueryBuilder for a Model subclass. You rarely need to call this. Query builders are created using the [Model.query()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#query) and other query methods. ##### Arguments @@ -18,7 +18,7 @@ modelClass|ModelClass|A Model class constructor Type|Description ----|----------------------------- -[QueryBuilder](/api/query-builder/)|The created query builder +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)|The created query builder ## parseRelationExpression() @@ -26,13 +26,13 @@ Type|Description const exprObj = QueryBuilder.parseRelationExpression(expr); ``` -Parses a string relation expression into the [object notation](/api/types/#relationexpression-object-notation). +Parses a string relation expression into the [object notation](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#relationexpression-object-notation). ##### Arguments Argument|Type|Description --------|----|-------------------- -expr|[RelationExpression](/api/types/#type-relationexpression)|A relation expression string or object. +expr|[RelationExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression)|A relation expression string or object. ##### Return value diff --git a/doc/api/types/README.md b/doc/api/types/README.md index 8731bf3e3..96156c698 100644 --- a/doc/api/types/README.md +++ b/doc/api/types/README.md @@ -4,7 +4,7 @@ sidebar: auto # Types -This page contains the documentation of all other types and classes than [Model](/api/model/) and [QueryBuilder](/api/query-builder/). There are two types of items on this page: +This page contains the documentation of all other types and classes than [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) and [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/). There are two types of items on this page: 1. `type`: A type is just a POJO (Plain Old Javascript Object) with a set of properties. 2. `class`: A class is a JavaScript class with properties and methods. @@ -14,29 +14,29 @@ This page contains the documentation of all other types and classes than [Model] Property|Type|Description --------|----|----------- relation|function|The relation type. One of `Model.BelongsToOneRelation`, `Model.HasOneRelation`, `Model.HasManyRelation`, `Model.ManyToManyRelation` and `Model.HasOneThroughRelation`. -modelClass|[Model](/api/model/)
string|Constructor of the related model class, an absolute path to a module that exports one or a path relative to [modelPaths](/api/model/static-properties.html#static-modelpaths) that exports a model class. -join|[RelationJoin](/api/types/#type-relationjoin)|Describes how the models are related to each other. See [RelationJoin](/api/types/#type-relationjoin). -modify|function([QueryBuilder](/api/query-builder/))
string
object|Optional modifier for the relation query. If specified as a function, it will be called each time before fetching the relation. If specified as a string, named filter with specified name will be applied each time when fetching the relation. If specified as an object, it will be used as an additional query parameter - e. g. passing {name: 'Jenny'} would additionally narrow fetched rows to the ones with the name 'Jenny'. -filter|function([QueryBuilder](/api/query-builder/))
string
object|Alias for modify. -beforeInsert|function([Model](/api/model/), [QueryContext](/api/query-builder/other-methods.html#context))|Optional insert hook that is called for each inserted model instance. This function can be async. +modelClass|[Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/)
string|Constructor of the related model class, an absolute path to a module that exports one or a path relative to [modelPaths](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modelpaths) that exports a model class. +join|[RelationJoin](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationjoin)|Describes how the models are related to each other. See [RelationJoin](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationjoin). +modify|function([QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/))
string
object|Optional modifier for the relation query. If specified as a function, it will be called each time before fetching the relation. If specified as a string, named filter with specified name will be applied each time when fetching the relation. If specified as an object, it will be used as an additional query parameter - e. g. passing {name: 'Jenny'} would additionally narrow fetched rows to the ones with the name 'Jenny'. +filter|function([QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/))
string
object|Alias for modify. +beforeInsert|function([Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/), [QueryContext](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context))|Optional insert hook that is called for each inserted model instance. This function can be async. ## `type` RelationJoin Property|Type|Description --------|----|----------- -from|string
[ReferenceBuilder](/api/objection/#ref)
Array|The relation column in the owner table. Must be given with the table name. For example `persons.id`. Composite key can be specified using an array of columns e.g. `['persons.a', 'persons.b']`. Note that neither this nor `to` need to be foreign keys or primary keys. You can join any column to any column. You can even join nested json fields using the [ref](/api/objection/#ref) helper. -to|string
[ReferenceBuilder](/api/objection/#ref)
Array|The relation column in the related table. Must be given with the table name. For example `movies.id`. Composite key can be specified using an array of columns e.g. `['movies.a', 'movies.b']`. Note that neither this nor `from` need to be foreign keys or primary keys. You can join any column to any column. You can even join nested json fields using the [ref](/api/objection/#ref) helper. -through|[RelationThrough](/api/types/#type-relationthrough)|Describes the join table if the models are related through one. +from|string
[ReferenceBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref)
Array|The relation column in the owner table. Must be given with the table name. For example `persons.id`. Composite key can be specified using an array of columns e.g. `['persons.a', 'persons.b']`. Note that neither this nor `to` need to be foreign keys or primary keys. You can join any column to any column. You can even join nested json fields using the [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref) helper. +to|string
[ReferenceBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref)
Array|The relation column in the related table. Must be given with the table name. For example `movies.id`. Composite key can be specified using an array of columns e.g. `['movies.a', 'movies.b']`. Note that neither this nor `from` need to be foreign keys or primary keys. You can join any column to any column. You can even join nested json fields using the [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref) helper. +through|[RelationThrough](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationthrough)|Describes the join table if the models are related through one. ## `type` RelationThrough Property|Type|Description --------|----|----------- -from|string
[ReferenceBuilder](/api/objection/#ref)
Array|The column that is joined to `from` property of the `RelationJoin`. For example `Person_movies.actorId` where `Person_movies` is the join table. Composite key can be specified using an array of columns e.g. `['persons_movies.a', 'persons_movies.b']`. You can join nested json fields using the [ref](/api/objection/#ref) helper. -to|string
[ReferenceBuilder](/api/objection/#ref)
Array|The column that is joined to `to` property of the `RelationJoin`. For example `Person_movies.movieId` where `Person_movies` is the join table. Composite key can be specified using an array of columns e.g. `['persons_movies.a', 'persons_movies.b']`. You can join nested json fields using the [ref](/api/objection/#ref) helper. +from|string
[ReferenceBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref)
Array|The column that is joined to `from` property of the `RelationJoin`. For example `Person_movies.actorId` where `Person_movies` is the join table. Composite key can be specified using an array of columns e.g. `['persons_movies.a', 'persons_movies.b']`. You can join nested json fields using the [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref) helper. +to|string
[ReferenceBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref)
Array|The column that is joined to `to` property of the `RelationJoin`. For example `Person_movies.movieId` where `Person_movies` is the join table. Composite key can be specified using an array of columns e.g. `['persons_movies.a', 'persons_movies.b']`. You can join nested json fields using the [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref) helper. modelClass|string
ModelClass|If you have a model class for the join table, you should specify it here. This is optional so you don't need to create a model class if you don't want to. -extra|string[]
Object|Join table columns listed here are automatically joined to the related objects when they are fetched and automatically written to the join table instead of the related table on insert. The values can be aliased by providing an object `{propertyName: 'columnName', otherPropertyName: 'otherColumnName'} instead of array` See [this recipe](/recipes/extra-properties.html) for more info. -beforeInsert|function([Model](/api/model/), [QueryContext](/api/query-builder/other-methods.html#context))|Optional insert hook that is called for each inserted join table model instance. This function can be async. +extra|string[]
Object|Join table columns listed here are automatically joined to the related objects when they are fetched and automatically written to the join table instead of the related table on insert. The values can be aliased by providing an object `{propertyName: 'columnName', otherPropertyName: 'otherColumnName'} instead of array` See [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/extra-properties.md) for more info. +beforeInsert|function([Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/), [QueryContext](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#context))|Optional insert hook that is called for each inserted join table model instance. This function can be async. ## `type` ModelOptions @@ -72,21 +72,21 @@ joinOperation|string|Which join type to use `['leftJoin', 'innerJoin', 'rightJoi Property|Type|Description --------|----|----------- -relate|boolean
string[]|If true, relations are related instead of inserted. Relate functionality can be enabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](/guide/query-examples.html#graph-upserts). -unrelate|boolean
string[]|If true, relations are unrelated instead of deleted. Unrelate functionality can be enabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](/guide/query-examples.html#graph-upserts). -insertMissing|boolean
string[]|If true, models that have identifiers _and_ are not found, are inserted. By default this is false and an error is thrown. This functionality can be enabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](/guide/query-examples.html#graph-upserts). -update|boolean
string[]|If true, update operations are performed instead of patch when altering existing models, affecting the way the data is validated. With update operations, all required fields need to be present in the data provided. This functionality can be enabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](/guide/query-examples.html#graph-upserts). -noInsert|boolean
string[]|If true, no inserts are performed. Inserts can be disabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](/guide/query-examples.html#graph-upserts). -noUpdate|boolean
string[]|If true, no updates are performed. Updates can be disabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](/guide/query-examples.html#graph-upserts). -noDelete|boolean
string[]|If true, no deletes are performed. Deletes can be disabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](/guide/query-examples.html#graph-upserts). -noRelate|boolean
string[]|If true, no relates are performed. Relate operations can be disabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](/guide/query-examples.html#graph-upserts). -noUnrelate|boolean
string[]|If true, no unrelate operations are performed. Unrelate operations can be disabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](/guide/query-examples.html#graph-upserts). +relate|boolean
string[]|If true, relations are related instead of inserted. Relate functionality can be enabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts). +unrelate|boolean
string[]|If true, relations are unrelated instead of deleted. Unrelate functionality can be enabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts). +insertMissing|boolean
string[]|If true, models that have identifiers _and_ are not found, are inserted. By default this is false and an error is thrown. This functionality can be enabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts). +update|boolean
string[]|If true, update operations are performed instead of patch when altering existing models, affecting the way the data is validated. With update operations, all required fields need to be present in the data provided. This functionality can be enabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts). +noInsert|boolean
string[]|If true, no inserts are performed. Inserts can be disabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts). +noUpdate|boolean
string[]|If true, no updates are performed. Updates can be disabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts). +noDelete|boolean
string[]|If true, no deletes are performed. Deletes can be disabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts). +noRelate|boolean
string[]|If true, no relates are performed. Relate operations can be disabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts). +noUnrelate|boolean
string[]|If true, no unrelate operations are performed. Unrelate operations can be disabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-upserts). ## `type` InsertGraphOptions Property|Type|Description --------|----|----------- -relate|boolean
string[]|If true, models with an `id` are related instead of inserted. Relate functionality can be enabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](/guide/query-examples.html#graph-inserts). +relate|boolean
string[]|If true, models with an `id` are related instead of inserted. Relate functionality can be enabled for a subset of relations of the graph by providing a list of relation expressions. See the examples [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-inserts). ## `type` TableMetadataFetchOptions @@ -133,7 +133,7 @@ Caveats when using special characters in keys: 4. Keys containing square brackets and quotes `objectColumn:['Double."Quote".[]']` and `objectColumn:["Sinlge.'Quote'.[]"]` Column `{ "Double.\"Quote\".[]" : "I was referred", "Sinlge.'Quote'.[]" : "Mee too!" }` 99. Keys containing dots, square brackets, single quotes and double quotes in one json key is not currently supported -There are some special methods that accept `FieldExpression` strings directly, like [whereJsonSupersetOf](/api/query-builder/find-methods.html#wherejsonsupersetof) but you can use `FieldExpressions` anywhere with [ref](/api/objection/#ref). Here's an example: +There are some special methods that accept `FieldExpression` strings directly, like [whereJsonSupersetOf](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherejsonsupersetof) but you can use `FieldExpressions` anywhere with [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref). Here's an example: ```js const { ref } = require('objection'); @@ -213,7 +213,7 @@ const people = await Person console.log(people[0].children[0].movies[0].actors[0].pets[0].name); ``` -Relation expressions can have arguments. Arguments are used to refer to modifier functions (either [global](/api/model/static-properties.html#static-modifiers) or [local](/api/query-builder/eager-methods.html#eager)). Arguments are listed in parenthesis after the relation names like this: +Relation expressions can have arguments. Arguments are used to refer to modifier functions (either [global](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modifiers) or [local](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager)). Arguments are listed in parenthesis after the relation names like this: ```js Person @@ -339,9 +339,9 @@ The string expression in the comment is equivalent to the object expression belo ## `type` TransactionObject -This is nothing more than a knex transaction object. It can be used as a knex query builder, it can be [passed to objection queries](/guide/transactions.html#passing-around-a-transaction-object) and [models can be bound to it](/guide/transactions.html#binding-models-to-a-transaction) +This is nothing more than a knex transaction object. It can be used as a knex query builder, it can be [passed to objection queries](https://github.com/Vincit/objection.js/tree/v1/doc/guide/transactions.md#passing-around-a-transaction-object) and [models can be bound to it](https://github.com/Vincit/objection.js/tree/v1/doc/guide/transactions.md#binding-models-to-a-transaction) -See the section about [transactions](/guide/transactions.html) for more info and examples. +See the section about [transactions](https://github.com/Vincit/objection.js/tree/v1/doc/guide/transactions.md) for more info and examples. ### Instance Methods @@ -376,9 +376,9 @@ If `type` is anything else but `"ModelValidation"`, `data` can be any object tha Error of this class is thrown by default if validation of any input fails. By input we mean any data that can come from the outside world, like model instances (or POJOs), relation expressions object graphs etc. -You can replace this error by overriding [Model.createValidationError()](/api/model/static-methods.html#static-createvalidationerror) method. +You can replace this error by overriding [Model.createValidationError()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-createvalidationerror) method. -See the [error handling recipe](/recipes/error-handling.html) for more info. +See the [error handling recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/error-handling.md) for more info. Property|Type|Description --------|----|----------- @@ -423,17 +423,17 @@ const { NotFoundError } = require('objection'); throw new NotFoundError(data); ``` -Error of this class is thrown by default by [throwIfNotFound()](/api/query-builder/other-methods.html#throwifnotfound) +Error of this class is thrown by default by [throwIfNotFound()](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#throwifnotfound) -You can replace this error by overriding [Model.createNotFoundError()](/api/model/static-methods.html#static-createnotfounderror) method. +You can replace this error by overriding [Model.createNotFoundError()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-createnotfounderror) method. -See the [error handling recipe](/recipes/error-handling.html) for more info. +See the [error handling recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/error-handling.md) for more info. ## `class` Relation -`Relation` is a parsed and normalized instance of a [RelationMapping](/api/types/#type-relationmapping). `Relation`s can be accessed using the [getRelations](/api/model/static-methods.html#static-getrelations) method. +`Relation` is a parsed and normalized instance of a [RelationMapping](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationmapping). `Relation`s can be accessed using the [getRelations](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-getrelations) method. -`Relation` holds a [RelationProperty](/api/types/#class-relationproperty) instance for each property that is used to create the relationship between two tables. +`Relation` holds a [RelationProperty](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-relationproperty) instance for each property that is used to create the relationship between two tables. `Relation` is actually a base class for all relation types `BelongsToOneRelation`, `HasManyRelation` etc. You can use `instanceof` to determine the type of the relations (see the example on the right). Note that `HasOneRelation` is a subclass of `HasManyRelation` and `HasOneThroughRelation` is a subclass of `ManyToManyRelation`. Arrange your `instanceof` checks accordingly. @@ -442,12 +442,12 @@ Property|Type|Description name|string|Name of the relation. For example `pets` or `children`. ownerModelClass|function|The model class that has defined the relation. relatedModelClass|function|The model class of the related objects. -ownerProp|[RelationProperty](/api/types/#class-relationproperty)|The relation property in the `ownerModelClass`. -relatedProp|[RelationProperty](/api/types/#class-relationproperty)|The relation property in the `relatedModelClass`. -joinModelClass|function|The model class representing the join table. This class is automatically generated by Objection if none is provided in the `join.through.modelClass` setting of the relation mapping, see [RelationThrough](/api/types/#type-relationthrough). +ownerProp|[RelationProperty](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-relationproperty)|The relation property in the `ownerModelClass`. +relatedProp|[RelationProperty](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-relationproperty)|The relation property in the `relatedModelClass`. +joinModelClass|function|The model class representing the join table. This class is automatically generated by Objection if none is provided in the `join.through.modelClass` setting of the relation mapping, see [RelationThrough](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationthrough). joinTable|string|The name of the join table (only for `ManyToMany` and `HasOneThrough` relations). -joinTableOwnerProp|[RelationProperty](/api/types/#class-relationproperty)|The join table property pointing to `ownerProp` (only for `ManyToMany` and `HasOneThrough` relations). -joinTableRelatedProp|[RelationProperty](/api/types/#class-relationproperty)|The join table property pointing to `relatedProp` (only for `ManyToMany` and `HasOneThrough` relations). +joinTableOwnerProp|[RelationProperty](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-relationproperty)|The join table property pointing to `ownerProp` (only for `ManyToMany` and `HasOneThrough` relations). +joinTableRelatedProp|[RelationProperty](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-relationproperty)|The join table property pointing to `relatedProp` (only for `ManyToMany` and `HasOneThrough` relations). Note that `Relation` instances are actually instances of the relation classes used in `relationMappings`. For example: @@ -516,7 +516,7 @@ const col = property.fullCol(builder, index); ``` Returns the property's index:th column name with the correct table reference. Something like `"Table.column"`. -The first argument must be an objection [QueryBuilder](/api/types/#querybuilder) instance. +The first argument must be an objection [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#querybuilder) instance. #### ref() @@ -532,7 +532,7 @@ const ref = property.ref(builder, 0); builder.where(ref, '>', 10); ``` -Returns a [ReferenceBuilder](/api/objection/#ref) instance that points to the index:th column. +Returns a [ReferenceBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref) instance that points to the index:th column. #### patch() @@ -553,7 +553,7 @@ Appends an update operation for the index:th column into `patchObj` object. ## `class` ReferenceBuilder -An instance of this is returned from the [ref](/api/objection/#ref) helper function. +An instance of this is returned from the [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref) helper function. ### Instance Methods @@ -610,7 +610,7 @@ Gives an alias for the reference `.select(ref('age').as('yougness'))` ## `class` LiteralBuilder -An instance of this is returned from the [lit](/api/objection/#lit) helper function. If an object +An instance of this is returned from the [lit](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#lit) helper function. If an object is given as a value, it is cast to json by default. ### Instance Methods @@ -684,7 +684,7 @@ Gives an alias for the reference `.select(ref('age').as('yougness'))` ## `class` RawBuilder -An instance of this is returned from the [raw](/api/objection/#raw) helper function. +An instance of this is returned from the [raw](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#raw) helper function. ### Instance Methods @@ -700,7 +700,7 @@ You should use this instead of inserting the alias to the SQL to give objection const { Validator } = require('objection'); ``` -Abstract class from which model validators must be inherited. See the example for explanation. Also check out the [createValidator](/api/model/static-methods.html#static-createvalidator) method. +Abstract class from which model validators must be inherited. See the example for explanation. Also check out the [createValidator](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-createvalidator) method. #### Examples @@ -765,8 +765,8 @@ const { AjvValidator } = require('objection'); ``` The default [Ajv](https://github.com/epoberezkin/ajv) based json schema -validator. You can override the [createValidator](/api/model/static-methods.html#static-createvalidator) -method of [Model](/api/model/) like in the example to modify the validator. +validator. You can override the [createValidator](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-createvalidator) +method of [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) like in the example to modify the validator. #### Examples diff --git a/doc/guide/contributing.md b/doc/guide/contributing.md index 8ea8fa386..5661bb22f 100644 --- a/doc/guide/contributing.md +++ b/doc/guide/contributing.md @@ -22,7 +22,7 @@ For a pull request to get merged it needs to have the following things: 2. **Tests that verify the fix/feature.** It's possible to create a PR without tests and ask for someone else to write them but in that case it may take a long time or forever until someone finds time to do it. *Untested code will never get merged!* -3. **For features you also need to write documentation.** See the [development setup](/guide/contributing.html#development-setup) section for instructions on how to write documentation. +3. **For features you also need to write documentation.** See the [development setup](https://github.com/Vincit/objection.js/tree/v1/doc/guide/contributing.md#development-setup) section for instructions on how to write documentation. ## Development setup diff --git a/doc/guide/documents.md b/doc/guide/documents.md index 6bd799f21..b53003db4 100644 --- a/doc/guide/documents.md +++ b/doc/guide/documents.md @@ -1,9 +1,9 @@ # Documents -Objection.js makes it easy to store non-flat documents as table rows. All properties of a model that are marked as objects or arrays in the model's [jsonSchema](/api/model/static-properties.html#static-jsonschema) are automatically converted to JSON strings in the database and back to objects when read from the database. The database columns for the object properties can be normal text columns. Postgresql has the `json` and `jsonb` data types that can be used instead for better performance and possibility to [query the documents](http://www.postgresql.org/docs/9.4/static/functions-json.html). If you don't want to use [jsonSchema](/api/model/static-properties.html#static-jsonschema) you can mark properties as objects using the [jsonAttributes](/api/model/static-properties.html#static-jsonattributes) +Objection.js makes it easy to store non-flat documents as table rows. All properties of a model that are marked as objects or arrays in the model's [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema) are automatically converted to JSON strings in the database and back to objects when read from the database. The database columns for the object properties can be normal text columns. Postgresql has the `json` and `jsonb` data types that can be used instead for better performance and possibility to [query the documents](http://www.postgresql.org/docs/9.4/static/functions-json.html). If you don't want to use [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema) you can mark properties as objects using the [jsonAttributes](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonattributes) Model property. -The `address` property of the Person model is defined as an object in the [Person.jsonSchema](/api/model/static-properties.html#static-jsonschema): +The `address` property of the Person model is defined as an object in the [Person.jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema): ```js const jennifer = await Person diff --git a/doc/guide/getting-started.md b/doc/guide/getting-started.md index 716c0c5a5..bb17f5bf9 100644 --- a/doc/guide/getting-started.md +++ b/doc/guide/getting-started.md @@ -1,6 +1,6 @@ # Getting started -To use objection.js all you need to do is [initialize knex](http://knexjs.org/#Installation-node) and give the created knex instance to objection.js using [Model.knex(knex)](/api/model/static-methods.html#static-knex). Doing this installs the knex instance globally for all models (even the ones that have not been created yet). If you need to use multiple databases check out our [multi-tenancy recipe](/recipes/multitenancy-using-multiple-databases.html). +To use objection.js all you need to do is [initialize knex](http://knexjs.org/#Installation-node) and give the created knex instance to objection.js using [Model.knex(knex)](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-knex). Doing this installs the knex instance globally for all models (even the ones that have not been created yet). If you need to use multiple databases check out our [multi-tenancy recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/multitenancy-using-multiple-databases.md). The next step is to create some migrations and models and start using objection.js. The best way to get started is to check out one of our example projects: @@ -24,7 +24,7 @@ npm start We also have an [ESNext version of the example project](https://github.com/Vincit/objection.js/tree/master/examples/express-es7) that uses [Babel](https://babeljs.io/) for ESNext --> ES2015 transpiling and a [typescript version](https://github.com/Vincit/objection.js/tree/master/examples/express-ts). -Also check out our [API reference](/api/query-builder/) and [recipe book](/recipes/raw-queries.html). +Also check out our [API reference](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) and [recipe book](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/raw-queries.md). If installing the example project seems like too much work, here is a simple standalone example. Just copy this into a file and run it: diff --git a/doc/guide/models.md b/doc/guide/models.md index 3abd5c887..797609b65 100644 --- a/doc/guide/models.md +++ b/doc/guide/models.md @@ -1,12 +1,12 @@ # Models - A [Model](/api/model/) subclass represents a database table and instances of that class represent table rows. Models are created by inheriting from the [Model](/api/model/) class. A [Model](/api/model/) class can define [relationships](/guide/relations.html) (aka. relations, associations) to other models using the static [relationMappings](/api/model/static-properties.html#static-relationmappings) property. + A [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) subclass represents a database table and instances of that class represent table rows. Models are created by inheriting from the [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) class. A [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) class can define [relationships](https://github.com/Vincit/objection.js/tree/v1/doc/guide/relations.md) (aka. relations, associations) to other models using the static [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) property. -Models can optionally define a [jsonSchema](/api/model/static-properties.html#static-jsonschema) object that is used for input validation. Every time a [Model](/api/model/) instance is created, it is validated against the [jsonSchema](/api/model/static-properties.html#static-tablename). Note that [Model](/api/model/) instances are implicitly created whenever you call [insert](/api/query-builder/mutate-methods.html#insert), [insertGraph](/api/query-builder/mutate-methods.html#insertgraph), [patch](/api/query-builder/mutate-methods.html#patch) or any other method that takes in model properties (no validation is done when reading from the database). +Models can optionally define a [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema) object that is used for input validation. Every time a [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) instance is created, it is validated against the [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-tablename). Note that [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) instances are implicitly created whenever you call [insert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insert), [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph), [patch](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patch) or any other method that takes in model properties (no validation is done when reading from the database). -Each model must have an identifier column. The identifier column name can be set using the [idColumn](/api/model/static-properties.html#static-idcolumn) property. [idColumn](/api/model/static-properties.html#static-idcolumn) defaults to `"id"`. If your table's identifier is something else, you need to set [idColumn](/api/model/static-properties.html#static-idcolumn). Composite id can be set by giving an array of column names. Composite keys are first class citizens in objection. +Each model must have an identifier column. The identifier column name can be set using the [idColumn](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-idcolumn) property. [idColumn](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-idcolumn) defaults to `"id"`. If your table's identifier is something else, you need to set [idColumn](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-idcolumn). Composite id can be set by giving an array of column names. Composite keys are first class citizens in objection. -In objection, all configuration is done through [Model](/api/model/) classes and there is no global configuration or state. There is no "objection instance". This allows you to create isolated components and for example to use multiple different databases with different configurations in one app. Most of the time you want the same configuration for all models and a good pattern is to create a `BaseModel` class and inherit all your models from that. You can then add all shared configuration to `BaseModel`. See the static properties in [API Reference / Model](/api/model/static-properties.html#static-tablename) section for all available configuration options. +In objection, all configuration is done through [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) classes and there is no global configuration or state. There is no "objection instance". This allows you to create isolated components and for example to use multiple different databases with different configurations in one app. Most of the time you want the same configuration for all models and a good pattern is to create a `BaseModel` class and inherit all your models from that. You can then add all shared configuration to `BaseModel`. See the static properties in [API Reference / Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-tablename) section for all available configuration options. Note that in addition to `idColumn`, you don't define properties, indexes or anything else related to database schema in the model. In objection, database schema is considered a separate concern and should be handled using [migrations](https://knexjs.org/#Migrations). The reasoning is that in every non-trivial project will need migrations anyway. Managing the schema in two places (model and migrations) only makes things more complex in the long run. diff --git a/doc/guide/plugins.md b/doc/guide/plugins.md index 217b4a7a2..afc1200ea 100644 --- a/doc/guide/plugins.md +++ b/doc/guide/plugins.md @@ -1,6 +1,6 @@ # Plugins -A curated list of plugins and modules for objection. Only plugins that follow [the best practices](/guide/contributing.html#plugin-development-best-practices) are accepted on this list. Other modules like plugins for other frameworks and things that cannot be implemented following the best practices are an exception to this rule. If you are a developer of or otherwise know of a good plugin/module for objection, please create a pull request or an issue to get it added to this list. +A curated list of plugins and modules for objection. Only plugins that follow [the best practices](https://github.com/Vincit/objection.js/tree/v1/doc/guide/contributing.md#plugin-development-best-practices) are accepted on this list. Other modules like plugins for other frameworks and things that cannot be implemented following the best practices are an exception to this rule. If you are a developer of or otherwise know of a good plugin/module for objection, please create a pull request or an issue to get it added to this list. ## 3rd party plugins @@ -19,7 +19,7 @@ A curated list of plugins and modules for objection. Only plugins that follow [t ## Plugin development best practices -When possible, objection.js plugins should be implemented as [class mixins](http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/). A mixin is simply a function that takes a class as an argument and returns a subclass. Plugins should not modify [objection.Model](/api/model/), [objection.QueryBuilder](/api/query-builder/) or any other global variables directly. See the [example plugin](https://github.com/Vincit/objection.js/tree/master/examples/plugin) for more info. There is also [another example](https://github.com/Vincit/objection.js/tree/master/examples/plugin-with-options) that should be followed if your plugin takes options or configuration parameters. +When possible, objection.js plugins should be implemented as [class mixins](http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/). A mixin is simply a function that takes a class as an argument and returns a subclass. Plugins should not modify [objection.Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/), [objection.QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) or any other global variables directly. See the [example plugin](https://github.com/Vincit/objection.js/tree/master/examples/plugin) for more info. There is also [another example](https://github.com/Vincit/objection.js/tree/master/examples/plugin-with-options) that should be followed if your plugin takes options or configuration parameters. Mixin is just a function that takes a class and returns an extended subclass. diff --git a/doc/guide/query-examples.md b/doc/guide/query-examples.md index 71715d34d..7999d3473 100644 --- a/doc/guide/query-examples.md +++ b/doc/guide/query-examples.md @@ -4,23 +4,23 @@ sidebarDepth: 3 # Query examples -The `Person` model used in the examples is defined [here](/guide/models.html#examples). +The `Person` model used in the examples is defined [here](https://github.com/Vincit/objection.js/tree/v1/doc/guide/models.md#examples). -All queries are started with one of the [Model](/api/model/) methods [query](/api/model/static-methods.html#static-query), [$query](/api/model/instance-methods.html#query) or [$relatedQuery](/api/model/instance-methods.html#relatedquery). All these methods return a [QueryBuilder](/api/query-builder/) instance that can be used just like a [knex QueryBuilder](http://knexjs.org/#Builder) but they also have a bunch of methods added by objection. +All queries are started with one of the [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) methods [query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query), [$query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query) or [$relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery). All these methods return a [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) instance that can be used just like a [knex QueryBuilder](http://knexjs.org/#Builder) but they also have a bunch of methods added by objection. ## Basic queries ### Find queries -Find queries can be created by calling [Model.query()](/api/model/static-methods.html#static-query) and chaining query builder methods for the returned -[QueryBuilder](/api/query-builder/) instance. +Find queries can be created by calling [Model.query()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query) and chaining query builder methods for the returned +[QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) instance. In addition to the examples here, you can find more examples behind these links. -* [subqueries](/recipes/subqueries.html) -* [raw queries](/recipes/raw-queries.html) +* [subqueries](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/subqueries.md) +* [raw queries](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/raw-queries.md) - There's also a large amount of examples in the [API documentation](/api/query-builder/). + There's also a large amount of examples in the [API documentation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/). ##### Examples @@ -50,7 +50,7 @@ console.log('there are', people.length, 'People in total'); select "people".* from "people" ``` -The return value of the [query](/api/model/static-methods.html#static-query) method is an instance of [QueryBuilder](/api/query-builder/) that has all the methods a [knex QueryBuilder](http://knexjs.org/#Builder) has and a lot more. Here is a simple example that uses some of them: +The return value of the [query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query) method is an instance of [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) that has all the methods a [knex QueryBuilder](http://knexjs.org/#Builder) has and a lot more. Here is a simple example that uses some of them: ```js const middleAgedJennifers = await Person @@ -106,7 +106,7 @@ and exists ( order by "persons"."lastName" asc ``` -In addition to knex methods, the [QueryBuilder](/api/query-builder/) has a lot of helpers for dealing with relations like the [joinRelation](/api/query-builder/join-methods.html#joinrelation) method: +In addition to knex methods, the [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) has a lot of helpers for dealing with relations like the [joinRelation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/join-methods.md#joinrelation) method: ```js const people = await Person @@ -150,12 +150,12 @@ order by "lastName" asc ### Insert queries -Insert queries are created by chaining the [insert](/api/query-builder/mutate-methods.html#insert) method to the query. See the [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) method for inserting object graphs. +Insert queries are created by chaining the [insert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insert) method to the query. See the [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) method for inserting object graphs. In addition to the examples here, you can find more examples behind these links. -* [insert API reference](/api/query-builder/mutate-methods.html#insert) -* [graph inserts](/guide/query-examples.html#graph-inserts) +* [insert API reference](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insert) +* [graph inserts](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#graph-inserts) ##### Examples @@ -175,12 +175,12 @@ insert into "persons" ("firstName", "lastName") values ('Jennifer', 'Lawrence') ### Update queries -Update queries are created by chaining the [update](/api/query-builder/mutate-methods.html#update) or [patch](/api/query-builder/mutate-methods.html#patch) method to the query. [patch](/api/query-builder/mutate-methods.html#patch) and [update](/api/query-builder/mutate-methods.html#update) return the number of updated rows. If you want the freshly updated model as a result you can use the helper method [patchAndFetchById](/api/query-builder/mutate-methods.html#patchandfetchbyid) and [updateAndFetchById](/api/query-builder/mutate-methods.html#updateandfetchbyid). On postgresql you can simply chain [.returning('*')](/api/query-builder/find-methods.html#returning) or take a look at [this recipe](/recipes/returning-tricks.html) for more ideas. See [update](/api/query-builder/mutate-methods.html#update) and [patch](/api/query-builder/mutate-methods.html#patch) API documentation for discussion about their differences. +Update queries are created by chaining the [update](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#update) or [patch](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patch) method to the query. [patch](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patch) and [update](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#update) return the number of updated rows. If you want the freshly updated model as a result you can use the helper method [patchAndFetchById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patchandfetchbyid) and [updateAndFetchById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#updateandfetchbyid). On postgresql you can simply chain [.returning('*')](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#returning) or take a look at [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/returning-tricks.md) for more ideas. See [update](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#update) and [patch](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patch) API documentation for discussion about their differences. In addition to the examples here, you can find more examples behind these links. -* [patch API reference](/api/query-builder/mutate-methods.html#patch) -* [raw queries](/recipes/raw-queries.html) +* [patch API reference](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patch) +* [raw queries](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/raw-queries.md) ##### Examples @@ -230,9 +230,9 @@ select "persons".* from "persons" where "id" = 246 ### Delete queries -Delete queries are created by chaining the [delete](/api/query-builder/mutate-methods.html#delete) method to the query. +Delete queries are created by chaining the [delete](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#delete) method to the query. -NOTE: The return value of the query will be the number of deleted rows. *If you're using Postgres take a look at [this recipe](/recipes/returning-tricks.html) if you'd like the deleted rows to be returned as Model instances*. +NOTE: The return value of the query will be the number of deleted rows. *If you're using Postgres take a look at [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/returning-tricks.md) if you'd like the deleted rows to be returned as Model instances*. ##### Examples @@ -263,7 +263,7 @@ console.log(numDeleted, 'people were deleted'); delete from "persons" where lower("firstName") like '%ennif%' ``` -You can always use [subqueries](/recipes/subqueries.html), [raw](/api/objection/#raw), [ref](/api/objection/#ref), [lit](/api/objection/#lit) and all query building methods with [delete](/api/query-builder/mutate-methods.html#delete) queries, just like with every query in objection. With some databases, you cannot use joins with deletes (db restriction, not objection). You can replace joins with subqueries like this: +You can always use [subqueries](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/subqueries.md), [raw](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#raw), [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref), [lit](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#lit) and all query building methods with [delete](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#delete) queries, just like with every query in objection. With some databases, you cannot use joins with deletes (db restriction, not objection). You can replace joins with subqueries like this: ```js // This query deletes all people that have a pet named "Fluffy". @@ -311,13 +311,13 @@ where exists ( ## Relation queries -While the static [query](/api/model/static-methods.html#static-query) method can be used to create a query to a whole table [$relatedQuery](/api/model/instance-methods.html#relatedquery) method can be used to query a single relation. [$relatedQuery](/api/model/instance-methods.html#relatedquery) returns an instance of [QueryBuilder](/api/query-builder/) just like the [query](/api/model/static-methods.html#static-query) method. +While the static [query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query) method can be used to create a query to a whole table [$relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) method can be used to query a single relation. [$relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) returns an instance of [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) just like the [query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query) method. ### Find queries -Simply call [$relatedQuery('relationName')](/api/model/instance-methods.html#relatedquery) for a model _instance_ to fetch a relation for it. The relation name is given as the only argument. The return value is a [QueryBuilder](/api/query-builder/) so you once again have all the query methods at your disposal. In many cases it's more convenient to use [eager loading](/guide/query-examples.html#eager-loading) to fetch relations. [$relatedQuery](/api/model/instance-methods.html#relatedquery) is better when you only need one relation and you need to filter the query extensively. +Simply call [$relatedQuery('relationName')](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) for a model _instance_ to fetch a relation for it. The relation name is given as the only argument. The return value is a [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) so you once again have all the query methods at your disposal. In many cases it's more convenient to use [eager loading](https://github.com/Vincit/objection.js/tree/v1/doc/guide/query-examples.md#eager-loading) to fetch relations. [$relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) is better when you only need one relation and you need to filter the query extensively. -By default the fetched related models are assigned to the parent model to a property by the same name as the relation. For example in our `person.$relatedQuery('pets')` example query, the return value would be assigned to `person.pets`. This behaviour can be modified using [relatedFindQueryMutates](/api/model/static-properties.html#static-relatedfindquerymutates). Also check out [$setRelated](/api/model/instance-methods.html#setrelated) and [$appendRelated](/api/model/instance-methods.html#appendrelated) helpers. +By default the fetched related models are assigned to the parent model to a property by the same name as the relation. For example in our `person.$relatedQuery('pets')` example query, the return value would be assigned to `person.pets`. This behaviour can be modified using [relatedFindQueryMutates](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relatedfindquerymutates). Also check out [$setRelated](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#setrelated) and [$appendRelated](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#appendrelated) helpers. ##### Examples @@ -341,10 +341,10 @@ order by "name" asc ### Insert queries -Chain the [insert](/api/query-builder/mutate-methods.html#insert) method to a [$relatedQuery](/api/model/instance-methods.html#relatedquery) call to insert a related object for a model _instance_. The query inserts a new object to the related table and updates the needed tables to create the relation. In case of many-to-many relation a row is inserted to the join table etc. Also check out [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) method for an alternative way to insert related models. +Chain the [insert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insert) method to a [$relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) call to insert a related object for a model _instance_. The query inserts a new object to the related table and updates the needed tables to create the relation. In case of many-to-many relation a row is inserted to the join table etc. Also check out [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) method for an alternative way to insert related models. -By default the inserted related models are appended to the parent model to a property by the same name as the relation. For example in our `person.$relatedQuery('pets').insert(obj)` example query, the return value would be appended to `person.pets`. This behaviour can be modified using [relatedInsertQueryMutates](/api/model/static-properties.html#static-relatedinsertquerymutates). Also check out the [$setRelated](/api/model/instance-methods.html#setrelated) and -[$appendRelated](/api/model/instance-methods.html#appendrelated) helpers. +By default the inserted related models are appended to the parent model to a property by the same name as the relation. For example in our `person.$relatedQuery('pets').insert(obj)` example query, the return value would be appended to `person.pets`. This behaviour can be modified using [relatedInsertQueryMutates](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relatedinsertquerymutates). Also check out the [$setRelated](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#setrelated) and +[$appendRelated](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#appendrelated) helpers. ##### Examples @@ -363,7 +363,7 @@ console.log(person.pets.indexOf(fluffy) !== -1); // --> true insert into "animals" ("name", "ownerId") values ('Fluffy', 1) ``` -If you want to write columns to the join table of a many-to-many relation you first need to specify the columns in the `extra` array of the `through` object in [relationMappings](/api/model/static-properties.html#static-relationmappings) (see the examples behind the link). For example, if you specified an array `extra: ['awesomeness']` in [relationMappings](/api/model/static-properties.html#static-relationmappings) then `awesomeness` is written to the join table in the following example: +If you want to write columns to the join table of a many-to-many relation you first need to specify the columns in the `extra` array of the `through` object in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) (see the examples behind the link). For example, if you specified an array `extra: ['awesomeness']` in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) then `awesomeness` is written to the join table in the following example: ```js // `person` is an instance of `Person` model. @@ -382,31 +382,31 @@ insert into "persons_movies" ("movieId", "personId", "awesomeness") values (14, 25, 9001) ``` -See [this recipe](/recipes/extra-properties.html) for more information about `extra` properties. +See [this recipe](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/extra-properties.md) for more information about `extra` properties. ### Update queries -See the [API documentation](/api/query-builder/mutate-methods.html#update) of `update` method. +See the [API documentation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#update) of `update` method. ### Delete queries -See the [API documentation](/api/query-builder/mutate-methods.html#delete) of `delete` method. +See the [API documentation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#delete) of `delete` method. ### Relate queries -See the [API documentation](/api/query-builder/mutate-methods.html#relate) of `relate` method. +See the [API documentation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#relate) of `relate` method. ### Unrelate queries -See the [API documentation](/api/query-builder/mutate-methods.html#unrelate) of `unrelate` method. +See the [API documentation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#unrelate) of `unrelate` method. ## Eager loading -You can fetch an arbitrary graph of relations for the results of any query by chaining the [eager](/api/query-builder/eager-methods.html#eager) method. [eager](/api/query-builder/eager-methods.html#eager) takes a [relation expression](/api/types/#type-relationexpression) string as a parameter. In addition to making your life easier, eager queries avoid the "select N+1" problem and provide a great performance. +You can fetch an arbitrary graph of relations for the results of any query by chaining the [eager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager) method. [eager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager) takes a [relation expression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationexpression) string as a parameter. In addition to making your life easier, eager queries avoid the "select N+1" problem and provide a great performance. -Because the eager expressions are strings (there's also an optional [object notation](/api/types/#relationexpression-object-notation)) they can be easily passed for example as a query parameter of an HTTP request. However, allowing the client to execute expressions like this without any limitations is not very secure. Therefore the [QueryBuilder](/api/query-builder/) has the [allowEager](/api/query-builder/eager-methods.html#alloweager) method. [allowEager](/api/query-builder/eager-methods.html#alloweager) can be used to limit the allowed eager expression to a certain subset. +Because the eager expressions are strings (there's also an optional [object notation](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#relationexpression-object-notation)) they can be easily passed for example as a query parameter of an HTTP request. However, allowing the client to execute expressions like this without any limitations is not very secure. Therefore the [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) has the [allowEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#alloweager) method. [allowEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#alloweager) can be used to limit the allowed eager expression to a certain subset. -By giving expression `[pets, children.pets]` for [allowEager](/api/query-builder/eager-methods.html#alloweager) the value passed to [eager](/api/query-builder/eager-methods.html#eager) is allowed to be one of: +By giving expression `[pets, children.pets]` for [allowEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#alloweager) the value passed to [eager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager) is allowed to be one of: * `'pets'` * `'children'` @@ -421,10 +421,10 @@ Examples of expressions that would cause the query to be rejected: * `'[pets, children.children]'` * `'notEvenAnExistingRelation'` -In addition to the [eager](/api/query-builder/eager-methods.html#eager) method, relations can be fetched using the [loadRelated](/api/model/static-properties.html#static-loadrelated) and -[$loadRelated](/api/model/instance-methods.html#loadrelated) methods. +In addition to the [eager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager) method, relations can be fetched using the [loadRelated](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-loadrelated) and +[$loadRelated](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#loadrelated) methods. -By default eager loading is done using multiple separate queries (for details see [this blog post](https://www.vincit.fi/en/blog/nested-eager-loading-and-inserts-with-objection-js/)). You can choose to use a join based eager loading algorithm that only performs one single query to fetch the whole eager tree. You can select which algorithm to use per query using [eagerAlgorithm](/api/query-builder/eager-methods.html#eageralgorithm) method or per model by setting the [defaultEagerAlgorithm](/api/model/static-properties.html#static-defaulteageralgorithm) property. All algorithms have their strengths and weaknesses, which are discussed in detail [here](/api/query-builder/eager-methods.html#eager). +By default eager loading is done using multiple separate queries (for details see [this blog post](https://www.vincit.fi/en/blog/nested-eager-loading-and-inserts-with-objection-js/)). You can choose to use a join based eager loading algorithm that only performs one single query to fetch the whole eager tree. You can select which algorithm to use per query using [eagerAlgorithm](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eageralgorithm) method or per model by setting the [defaultEagerAlgorithm](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-defaulteageralgorithm) property. All algorithms have their strengths and weaknesses, which are discussed in detail [here](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager). ##### Examples @@ -457,7 +457,7 @@ console.log(people[1].children[2].pets[1].name); console.log(people[1].children[2].children[0].name); ``` -Here's the previous query using the optional [object notation](/api/types/#relationexpression-object-notation) +Here's the previous query using the optional [object notation](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#relationexpression-object-notation) ```js const people = await Person @@ -494,7 +494,7 @@ const people = await Person console.log(people[0].children[0].children[0].children[0].firstName); ``` -Relations can be modified using the [modifyEager](/api/query-builder/other-methods.html#modifyeager) method: +Relations can be modified using the [modifyEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#modifyeager) method: ```js const people = await Person @@ -528,7 +528,7 @@ console.log(people[0].children[0].pets[0].name); console.log(people[0].children[0].movies[0].id); ``` -Reusable named filters can be defined for models using [modifiers](/api/model/static-properties.html#static-modifiers) +Reusable named filters can be defined for models using [modifiers](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-modifiers) ```js // Person.js @@ -598,7 +598,7 @@ console.log(people[0].kids[0].dogs[0].name); console.log(people[0].kids[0].movies[0].id); ``` -Example usage for [allowEager](/api/query-builder/eager-methods.html#alloweager) in an express route: +Example usage for [allowEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#alloweager) in an express route: ```js expressApp.get('/people', async (req, res, next) => { @@ -611,7 +611,7 @@ expressApp.get('/people', async (req, res, next) => { }); ``` -Eager loading algorithm can be changed using the [eagerAlgorithm](/api/query-builder/eager-methods.html#eageralgorithm) method: +Eager loading algorithm can be changed using the [eagerAlgorithm](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eageralgorithm) method: ```js const people = await Person @@ -630,13 +630,13 @@ const people = await Person ## Graph inserts -Arbitrary relation graphs can be inserted using the [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) method. This is best explained using examples, so check them out. +Arbitrary relation graphs can be inserted using the [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) method. This is best explained using examples, so check them out. -See the [allowInsert](/api/query-builder/mutate-methods.html#allowinsert) method if you need to limit which relations can be inserted using [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) method to avoid security issues. [allowInsert](/api/query-builder/mutate-methods.html#allowinsert) works like [allowEager](/api/query-builder/eager-methods.html#alloweager). +See the [allowInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#allowinsert) method if you need to limit which relations can be inserted using [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) method to avoid security issues. [allowInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#allowinsert) works like [allowEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#alloweager). If you are using Postgres the inserts are done in batches for maximum performance. On other databases the rows need to be inserted one at a time. This is because postgresql is the only database engine that returns the identifiers of all inserted rows and not just the first or the last one. -[insertGraph](/api/query-builder/mutate-methods.html#insertgraph) operation is __not__ atomic by default! You need to start a transaction and pass it to the query using any of the supported ways. See the section about [transactions](/guide/transactions.html) for more information. +[insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) operation is __not__ atomic by default! You need to start a transaction and pass it to the query using any of the supported ways. See the section about [transactions](https://github.com/Vincit/objection.js/tree/v1/doc/guide/transactions.md) for more information. You can read more about graph inserts from [this blog post](https://www.vincit.fi/en/blog/nested-eager-loading-and-inserts-with-objection-js/). @@ -665,7 +665,7 @@ const graph = await Person }); ``` -The query above will insert 'Sylvester', 'Sage' and 'Fluffy' into db and create relationships between them as defined in the [relationMappings](/api/model/static-properties.html#static-relationmappings) of the models. Technically [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) builds a dependency graph from the object graph and inserts the models that don't depend on any other models until the whole graph is inserted. +The query above will insert 'Sylvester', 'Sage' and 'Fluffy' into db and create relationships between them as defined in the [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) of the models. Technically [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) builds a dependency graph from the object graph and inserts the models that don't depend on any other models until the whole graph is inserted. If you need to refer to the same model in multiple places you can use the special properties `#id` and `#ref` like this: @@ -691,7 +691,7 @@ await Person }]); ``` -The query above will insert only one movie (the 'Silver Linings Playbook') but both 'Jennifer' and 'Bradley' will have the movie related to them through the many-to-many relation `movies`. The `#id` can be any string. There are no format or length requirements for them. It is quite easy to create circular dependencies using `#id` and `#ref`. Luckily [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) detects them and rejects the query with a clear error message. +The query above will insert only one movie (the 'Silver Linings Playbook') but both 'Jennifer' and 'Bradley' will have the movie related to them through the many-to-many relation `movies`. The `#id` can be any string. There are no format or length requirements for them. It is quite easy to create circular dependencies using `#id` and `#ref`. Luckily [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) detects them and rejects the query with a clear error message. You can refer to the properties of other models anywhere in the graph using expressions of format `#ref{.}` as long as the reference doesn't create a circular dependency. For example: @@ -793,17 +793,17 @@ await Person ## Graph upserts -Arbitrary relation graphs can be upserted (insert + update + delete) using the [upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph) method. This is best explained using examples, so check them out. +Arbitrary relation graphs can be upserted (insert + update + delete) using the [upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph) method. This is best explained using examples, so check them out. -By default [upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph) method updates the objects that have an id, inserts objects that don't have an id and deletes all objects that are not present. This functionality can be modified in many ways by providing [UpsertGraphOptions](/api/types/#type-upsertgraphoptions) object as the second argument. +By default [upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph) method updates the objects that have an id, inserts objects that don't have an id and deletes all objects that are not present. This functionality can be modified in many ways by providing [UpsertGraphOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-upsertgraphoptions) object as the second argument. -The [upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph) method works a little different than the other update and patch methods. When using [upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph) any `where` or `having` methods are ignored. The models are updated based on the id properties in the graph. This is also clarified in the examples. +The [upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph) method works a little different than the other update and patch methods. When using [upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph) any `where` or `having` methods are ignored. The models are updated based on the id properties in the graph. This is also clarified in the examples. -[upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph) uses [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) under the hood for inserts. That means that you can insert object graphs for relations and use all [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) features like `#ref` references. +[upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph) uses [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) under the hood for inserts. That means that you can insert object graphs for relations and use all [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) features like `#ref` references. -[upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph) operation is __not__ atomic by default! You need to start a transaction and pass it to the query using any of the supported ways. See the section about [transactions](/guide/transactions.html) for more information. +[upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph) operation is __not__ atomic by default! You need to start a transaction and pass it to the query using any of the supported ways. See the section about [transactions](https://github.com/Vincit/objection.js/tree/v1/doc/guide/transactions.md) for more information. -See the [allowUpsert](/api/query-builder/mutate-methods.html#allowupsert) method if you need to limit which relations can be modified using [upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph) method to avoid security issues. [allowUpsert](/api/query-builder/mutate-methods.html#allowupsert) works like [allowInsert](/api/query-builder/mutate-methods.html#allowinsert). +See the [allowUpsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#allowupsert) method if you need to limit which relations can be modified using [upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph) method to avoid security issues. [allowUpsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#allowupsert) works like [allowInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#allowinsert). ##### Examples @@ -858,7 +858,7 @@ For the following examples, assume this is the content of the database: }] ``` -By default [upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph) method updates the objects that have an id, inserts objects that don't have an id and deletes all objects that are not present. Off course the delete only applies to relations and not the root. Here's a basic example: +By default [upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph) method updates the objects that have an id, inserts objects that don't have an id and deletes all objects that are not present. Off course the delete only applies to relations and not the root. Here's a basic example: ```js // The return value of `upsertGraph` is the input graph converted into @@ -977,7 +977,7 @@ await Person }, options); ``` -`relate` and `unrelate` (and all other [options](/api/types/#type-upsertgraphoptions) can also be lists of relation paths. In that case the option is only applied for the listed relations. +`relate` and `unrelate` (and all other [options](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-upsertgraphoptions) can also be lists of relation paths. In that case the option is only applied for the listed relations. ```js const options = { @@ -1032,4 +1032,4 @@ await Person }, options); ``` -You can disable updates, inserts, deletes etc. for the whole [upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph) operation or for individual relations by using the `noUpdate`, `noInsert`, `noDelete` etc. options. See [UpsertGraphOptions](/api/types/#type-upsertgraphoptions) docs for more info. +You can disable updates, inserts, deletes etc. for the whole [upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph) operation or for individual relations by using the `noUpdate`, `noInsert`, `noDelete` etc. options. See [UpsertGraphOptions](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-upsertgraphoptions) docs for more info. diff --git a/doc/guide/relations.md b/doc/guide/relations.md index f22927c10..82ad4dc11 100644 --- a/doc/guide/relations.md +++ b/doc/guide/relations.md @@ -1,6 +1,6 @@ # Relations -We already went through how to create relationships (aka. relations, associations) in the [models](/guide/models.html) section's examples but here's a list of all the available relation types in a nicely searchable place. See [this](/api/types/#type-relationmapping) API doc section for full documentation of the relation mapping parameters. +We already went through how to create relationships (aka. relations, associations) in the [models](https://github.com/Vincit/objection.js/tree/v1/doc/guide/models.md) section's examples but here's a list of all the available relation types in a nicely searchable place. See [this](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-relationmapping) API doc section for full documentation of the relation mapping parameters. Relationships are a very basic concept in relational databases and if you aren't familiar with it, you should spend some time googling it first. Basically there are three ways to create a relationship between two tables `A` and `B`: @@ -16,7 +16,7 @@ Relationships are a very basic concept in relational databases and if you aren't While relations are usually created between the primary key of one table and a foreign key reference of another table, objection has no such limitations. You can create relationship using any two columns (or any sets of columns). You can even create relation using values nested deep inside json columns. -If you've used other ORMs you may notice that objection's [relationMappings](/api/model/static-properties.html#static-relationmappings) are pretty verbose. There are couple of reasons for that: +If you've used other ORMs you may notice that objection's [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) are pretty verbose. There are couple of reasons for that: 1. For a new user, this style underlines what is happening, and which columns and tables are involved. diff --git a/doc/guide/transactions.md b/doc/guide/transactions.md index 3d361fc52..190789d3c 100644 --- a/doc/guide/transactions.md +++ b/doc/guide/transactions.md @@ -5,7 +5,7 @@ Transactions are atomic and isolated units of work in relational databases. If y ## Creating a transaction -In objection, a transaction can be started by calling the [objection.transaction](/api/objection/#transaction) function: +In objection, a transaction can be started by calling the [objection.transaction](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#transaction) function: ```js const { transaction } = require('objection'); @@ -24,7 +24,7 @@ try { } ``` -You need to pass a knex instance as the first argument. If you don't have a knex instance otherwise available you can always access it through any [Model](/api/model/) using [Model.knex()](/api/model/static-methods.html#static-knex) provided that you have installed the knex instance globally using [Model.knex(knex)](/api/model/static-methods.html#static-knex) at some point. +You need to pass a knex instance as the first argument. If you don't have a knex instance otherwise available you can always access it through any [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) using [Model.knex()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-knex) provided that you have installed the knex instance globally using [Model.knex(knex)](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-knex) at some point. The second argument is a callback that gets called with the transaction object as an argument once the transaction has been successfully started. The transaction object is actually just a [knex transaction object](http://knexjs.org/#Transactions) and you can start the transaction just as well using [knex.transaction](http://knexjs.org/#Transactions) function. @@ -52,12 +52,12 @@ try { After you have created a transaction, you need to tell objection which queries should be executed inside that transaction. There are two ways to do that: -1. [By passing the transaction object to each query](/guide/transactions.html#passing-around-a-transaction-object) -2. [By binding models to the transaction](/guide/transactions.html#binding-models-to-a-transaction) +1. [By passing the transaction object to each query](https://github.com/Vincit/objection.js/tree/v1/doc/guide/transactions.md#passing-around-a-transaction-object) +2. [By binding models to the transaction](https://github.com/Vincit/objection.js/tree/v1/doc/guide/transactions.md#binding-models-to-a-transaction) ### Passing around a transaction object -The most straight forwared way to use a transaction is to explicitly give it to each query you start. [query](/api/model/static-methods.html#static-query), [$query](/api/model/instance-methods.html#query) and [$relatedQuery](/api/model/instance-methods.html#relatedquery) accept a transaction as their last argument. +The most straight forwared way to use a transaction is to explicitly give it to each query you start. [query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query), [$query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query) and [$relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) accept a transaction as their last argument. ```js const { transaction } = require('objection'); @@ -84,7 +84,7 @@ try { } ``` -Note that you can pass either a normal knex instance or a transaction to [query](/api/model/static-methods.html#static-query), [$relatedQuery](/api/model/instance-methods.html#relatedquery) etc. allowing you to build helper functions and services that can be used with or without a transaction. When a transaction is not wanted, just pass in the normal knex instance (or nothing at all if you have installed the knex object globally using [Model.knex(knex)](/api/model/static-methods.html#static-knex)): +Note that you can pass either a normal knex instance or a transaction to [query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query), [$relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) etc. allowing you to build helper functions and services that can be used with or without a transaction. When a transaction is not wanted, just pass in the normal knex instance (or nothing at all if you have installed the knex object globally using [Model.knex(knex)](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-knex)): ```js // `db` can be either a transaction or a knex instance or even @@ -121,7 +121,7 @@ await insertPersonAndPet(person, pet); ### Binding models to a transaction -The second way to use transactions avoids passing around a transaction object by "binding" model classes to a transaction. You pass all models you want to bind as arguments to the [objection.transaction](/api/objection/#transaction) method and as the last argument you provide a callback that receives __copies__ of the models that have been bound to a newly started transaction. All queries started through the bound copies take part in the transaction and you don't need to pass around a transaction object. Note that the models passed to the callback are actual copies of the models passed as arguments to [objection.transaction](/api/objection/#transaction) and starting a query through any other object will __not__ be executed inside a transaction. +The second way to use transactions avoids passing around a transaction object by "binding" model classes to a transaction. You pass all models you want to bind as arguments to the [objection.transaction](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#transaction) method and as the last argument you provide a callback that receives __copies__ of the models that have been bound to a newly started transaction. All queries started through the bound copies take part in the transaction and you don't need to pass around a transaction object. Note that the models passed to the callback are actual copies of the models passed as arguments to [objection.transaction](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#transaction) and starting a query through any other object will __not__ be executed inside a transaction. ```js const { transaction } = require('objection'); @@ -148,7 +148,7 @@ try { } ``` -You only need to give the [objection.transaction](/api/objection/#transaction) function the model classes you use explicitly. All the related model classes are implicitly bound to the same transaction: +You only need to give the [objection.transaction](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#transaction) function the model classes you use explicitly. All the related model classes are implicitly bound to the same transaction: ```js const { transaction } = require('objection'); diff --git a/doc/guide/validation.md b/doc/guide/validation.md index 32a6319b4..ebc4b9cc4 100644 --- a/doc/guide/validation.md +++ b/doc/guide/validation.md @@ -1,10 +1,10 @@ # Validation -[JSON schema](http://json-schema.org/) validation can be enabled by setting the [jsonSchema](/api/model/static-properties.html#static-jsonschema) property of a model class. The validation is ran each time a [Model](/api/model/) instance is created. +[JSON schema](http://json-schema.org/) validation can be enabled by setting the [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema) property of a model class. The validation is ran each time a [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) instance is created. -You rarely need to call [$validate](/api/model/instance-methods.html#validate) method explicitly, but you can do it when needed. If validation fails a [ValidationError](/api/types/#class-validationerror) will be thrown. Since we use Promises, this usually means that a promise will be rejected with an instance of [ValidationError](/api/types/#class-validationerror). +You rarely need to call [$validate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#validate) method explicitly, but you can do it when needed. If validation fails a [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror) will be thrown. Since we use Promises, this usually means that a promise will be rejected with an instance of [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror). -See [the recipe book](/recipes/custom-validation.html) for instructions if you want to use some other validation library. +See [the recipe book](https://github.com/Vincit/objection.js/tree/v1/doc/recipes/custom-validation.md) for instructions if you want to use some other validation library. ## Examples @@ -46,7 +46,7 @@ try { } ``` -Error parameters returned by [ValidationError](/api/types/#class-validationerror) could be used to provide custom error messages: +Error parameters returned by [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror) could be used to provide custom error messages: ```js try { diff --git a/doc/recipes/composite-keys.md b/doc/recipes/composite-keys.md index 816b872a7..739c743f4 100644 --- a/doc/recipes/composite-keys.md +++ b/doc/recipes/composite-keys.md @@ -1,17 +1,17 @@ # Composite keys -Composite (compound) keys are fully supported. Just give an array of columns where you would normally give a single column name. Composite primary key can be specified by setting an array of column names to the [idColumn](/api/model/static-properties.html#static-idcolumn) of a model class. +Composite (compound) keys are fully supported. Just give an array of columns where you would normally give a single column name. Composite primary key can be specified by setting an array of column names to the [idColumn](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-idcolumn) of a model class. Here's a list of methods that may help working with composite keys: - * [whereComposite](/api/query-builder/find-methods.html#wherecomposite) - * [whereInComposite](/api/query-builder/find-methods.html#whereincomposite) - * [findById](/api/query-builder/find-methods.html#findbyid) - * [findByIds](/api/query-builder/find-methods.html#findbyids) - * [deleteById](/api/query-builder/mutate-methods.html#deletebyid) - * [updateAndFetchById](/api/query-builder/mutate-methods.html#updateandfetchbyid) - * [patchAndFetchById](/api/query-builder/mutate-methods.html#patchandfetchbyid) - * [$id](/api/model/instance-methods.html#id) + * [whereComposite](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherecomposite) + * [whereInComposite](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#whereincomposite) + * [findById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#findbyid) + * [findByIds](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#findbyids) + * [deleteById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#deletebyid) + * [updateAndFetchById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#updateandfetchbyid) + * [patchAndFetchById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patchandfetchbyid) + * [$id](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#id) ## Examples @@ -56,7 +56,7 @@ class Person extends Model { }; ``` -[findById](/api/query-builder/find-methods.html#findbyid): +[findById](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#findbyid): ```js await Person @@ -65,7 +65,7 @@ await Person ``` -[whereComposite](/api/query-builder/find-methods.html#wherecomposite): +[whereComposite](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#wherecomposite): ```js await Person @@ -73,7 +73,7 @@ await Person .whereComposite(['foo', 'bar'], [1, 'barValue']); ``` -[whereInComposite](/api/query-builder/find-methods.html#whereincomposite): +[whereInComposite](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#whereincomposite): ```js await Person diff --git a/doc/recipes/custom-id-column.md b/doc/recipes/custom-id-column.md index a4681e665..6b165fec4 100644 --- a/doc/recipes/custom-id-column.md +++ b/doc/recipes/custom-id-column.md @@ -1,6 +1,6 @@ # Custom id column -Name of the identifier column can be changed by setting the static [idColumn](/api/model/static-properties.html#static-idcolumn) property of a model class. Composite key can be defined by using an array of column names. +Name of the identifier column can be changed by setting the static [idColumn](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-idcolumn) property of a model class. Composite key can be defined by using an array of column names. ```js class Person extends Model { diff --git a/doc/recipes/custom-query-builder.md b/doc/recipes/custom-query-builder.md index 39b0b3388..7ca24181d 100644 --- a/doc/recipes/custom-query-builder.md +++ b/doc/recipes/custom-query-builder.md @@ -1,6 +1,6 @@ # Custom query builder -You can extend the [QueryBuilder](/api/query-builder/) returned by [query()](/api/model/static-methods.html#static-query), [$relatedQuery()](/api/model/instance-methods.html#relatedquery) and [$query()](/api/model/instance-methods.html#query) methods (and all other methods that create a [QueryBuilder](/api/query-builder/)) by setting the model class's static [QueryBuilder](/api/model/static-methods.html#static-querybuilder) property. +You can extend the [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) returned by [query()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query), [$relatedQuery()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) and [$query()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query) methods (and all other methods that create a [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/)) by setting the model class's static [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-querybuilder) property. ```js // MyQueryBuilder.js @@ -33,7 +33,7 @@ Now you can do this: await Person.query().upsert(person); ``` -If you want to set the custom query builder for all model classes you can just set the [QueryBuilder](/api/model/static-methods.html#static-querybuilder) property of the [Model](/api/model/) base class. A cleaner option would be to create your own Model subclass, set its [QueryBuilder](/api/query-builder/) property and inherit all your models from the custom Model class. +If you want to set the custom query builder for all model classes you can just set the [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-querybuilder) property of the [Model](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/) base class. A cleaner option would be to create your own Model subclass, set its [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) property and inherit all your models from the custom Model class. ```js @@ -53,7 +53,7 @@ const { BaseModel } = require('./BaseModel'); class Person extends BaseModel {} ``` -Whenever a [QueryBuilder](/api/query-builder/) instance is created it is done by calling the static [query()](/api/model/static-methods.html#static-query) method. If you don't need to add methods, but simply modify the query, you can override the [query()](/api/model/static-methods.html#static-query). +Whenever a [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) instance is created it is done by calling the static [query()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query) method. If you don't need to add methods, but simply modify the query, you can override the [query()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query). ```js class BaseModel extends Model { diff --git a/doc/recipes/custom-validation.md b/doc/recipes/custom-validation.md index 8a917a1b5..39c5d5eda 100644 --- a/doc/recipes/custom-validation.md +++ b/doc/recipes/custom-validation.md @@ -1,10 +1,10 @@ # Custom validation -If you want to use the json schema validation but add some custom validation on top of it you can override the [$beforeValidate](/api/model/instance-methods.html#beforevalidate) or [$afterValidate](/api/model/instance-methods.html#aftervalidate) method. +If you want to use the json schema validation but add some custom validation on top of it you can override the [$beforeValidate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforevalidate) or [$afterValidate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#aftervalidate) method. -If you need to do validation on insert or update you can throw exceptions from the [$beforeInsert](/api/model/instance-methods.html#beforeinsert) and [$beforeUpdate](/api/model/instance-methods.html#beforeupdate) methods. +If you need to do validation on insert or update you can throw exceptions from the [$beforeInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforeinsert) and [$beforeUpdate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforeupdate) methods. -If you don't want to use the built-in json schema validation, you can just ignore the [jsonSchema](/api/model/instance-methods.html#jsonschema) property. It is completely optional. If you want to use some other validation library you need to implement a custom [Validator](/api/types/#class-validator) (see the example). +If you don't want to use the built-in json schema validation, you can just ignore the [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#jsonschema) property. It is completely optional. If you want to use some other validation library you need to implement a custom [Validator](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validator) (see the example). ## Examples @@ -46,7 +46,7 @@ class Model { } ``` -Replace JSON schema validation with any other validation scheme by implementing a custom [Validator](/api/types/#class-validator): +Replace JSON schema validation with any other validation scheme by implementing a custom [Validator](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validator): ```js // MyCustomValidator.js diff --git a/doc/recipes/default-values.md b/doc/recipes/default-values.md index 9d69f5ed9..6830b0691 100644 --- a/doc/recipes/default-values.md +++ b/doc/recipes/default-values.md @@ -1,6 +1,6 @@ # Default values -You can set the default values for properties using the `default` property in [jsonSchema](/api/model/static-properties.html#static-jsonschema). +You can set the default values for properties using the `default` property in [jsonSchema](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-jsonschema). ```js @@ -20,4 +20,4 @@ class Person extends Model { } ``` -Note that you can also set default values in the database. See the documentation of knex and the appropriate database engine for more info. If you need to se dynamic default values, you can use the [$beforeInsert](/api/model/instance-methods.html#beforeinsert) hook. +Note that you can also set default values in the database. See the documentation of knex and the appropriate database engine for more info. If you need to se dynamic default values, you can use the [$beforeInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforeinsert) hook. diff --git a/doc/recipes/error-handling.md b/doc/recipes/error-handling.md index 2cf4f6f85..0a5b6c51a 100644 --- a/doc/recipes/error-handling.md +++ b/doc/recipes/error-handling.md @@ -2,11 +2,11 @@ Objection throws four kinds of errors: -1. [ValidationError](/api/types/#class-validationerror) when an input that could come from the outside world is invalid. These inputs - include model instances and POJOs, eager expressions object graphs etc. [ValidationError](/api/types/#class-validationerror) has +1. [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror) when an input that could come from the outside world is invalid. These inputs + include model instances and POJOs, eager expressions object graphs etc. [ValidationError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-validationerror) has a `type` property that can be used to distinguish between the different error types. -2. [NotFoundError](/api/types/#class-notfounderror) when [throwIfNotFound](/api/query-builder/other-methods.html#throwifnotfound) was called for a query and no +2. [NotFoundError](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#class-notfounderror) when [throwIfNotFound](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#throwifnotfound) was called for a query and no results were found. 3. Database errors (unique violation error etc.) are thrown by the database client libraries and the error types depend on the diff --git a/doc/recipes/extra-properties.md b/doc/recipes/extra-properties.md index 21c20df0a..66363bf40 100644 --- a/doc/recipes/extra-properties.md +++ b/doc/recipes/extra-properties.md @@ -26,7 +26,7 @@ exports.up = knex => { In this schema, `characterName` is the `extra` property. When we fetch movies for an actor, we want the movie objects to contain the `characterName` in addition to normal movie properties. -You can define your [relationMapping](/api/model/static-properties.html#static-relationmappings) like this: +You can define your [relationMapping](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) like this: ```js class Actor extends Model { @@ -90,4 +90,4 @@ await linda .where('movies.name', 'Curvature') ``` -`extra` properties also work with [eager](/api/query-builder/eager-methods.html#eager) [insertGraph](/api/query-builder/mutate-methods.html#insertgraph) and [upsertGraph](/api/query-builder/mutate-methods.html#upsertgraph). +`extra` properties also work with [eager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager) [insertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insertgraph) and [upsertGraph](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#upsertgraph). diff --git a/doc/recipes/joins.md b/doc/recipes/joins.md index 4bcb0bfc8..066cc2335 100644 --- a/doc/recipes/joins.md +++ b/doc/recipes/joins.md @@ -11,7 +11,7 @@ const people = await Person console.log(people[0].parentName); ``` -Objection also has helpers like the [joinRelation](/api/query-builder/join-methods.html#joinrelation) method family: +Objection also has helpers like the [joinRelation](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/join-methods.md#joinrelation) method family: ```js const people = await Person diff --git a/doc/recipes/json-queries.md b/doc/recipes/json-queries.md index 23420821a..e606a716e 100644 --- a/doc/recipes/json-queries.md +++ b/doc/recipes/json-queries.md @@ -1,8 +1,8 @@ # JSON queries -You can use the [ref](/api/objection/#ref) function from the main module to refer to json columns in queries. There is also a bunch of query building methods that have `Json` in their names. Check them out too. +You can use the [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref) function from the main module to refer to json columns in queries. There is also a bunch of query building methods that have `Json` in their names. Check them out too. -See [FieldExpression](/api/types/#type-fieldexpression) for more information about how to refer to json fields. +See [FieldExpression](https://github.com/Vincit/objection.js/tree/v1/doc/api/types/#type-fieldexpression) for more information about how to refer to json fields. Json queries currently only work with postgres. diff --git a/doc/recipes/multitenancy-using-multiple-databases.md b/doc/recipes/multitenancy-using-multiple-databases.md index e311a455a..46034072f 100644 --- a/doc/recipes/multitenancy-using-multiple-databases.md +++ b/doc/recipes/multitenancy-using-multiple-databases.md @@ -1,10 +1,10 @@ # Multitenancy using multiple databases -By default, the examples guide you to setup the database connection by calling [Model.knex(knex)](/api/model/static-methods.html#static-knex). This doesn't fly if you want to select the database based on the request as it sets the connection globally. There are (at least) two patterns for dealing with this kind of setup: +By default, the examples guide you to setup the database connection by calling [Model.knex(knex)](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-knex). This doesn't fly if you want to select the database based on the request as it sets the connection globally. There are (at least) two patterns for dealing with this kind of setup: ## Model binding pattern -If you have a different database for each tenant, a useful pattern is to add a middleware that adds the models to `req.models` hash and then _always_ use the models through `req.models` instead of requiring them directly. What [bindKnex](/api/model/static-properties.html#static-bindknex) method actually does is that it creates an anonymous subclass of the model class and sets its knex connection. That way the database connection doesn't change for the other requests that are currently being executed. +If you have a different database for each tenant, a useful pattern is to add a middleware that adds the models to `req.models` hash and then _always_ use the models through `req.models` instead of requiring them directly. What [bindKnex](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-bindknex) method actually does is that it creates an anonymous subclass of the model class and sets its knex connection. That way the database connection doesn't change for the other requests that are currently being executed. ```js @@ -60,7 +60,7 @@ app.get('/people', async (req, res) => { ## Knex passing pattern -Another option is to add the knex instance to the request using a middleware and not bind models at all (not even using [Model.knex()](/api/model/static-methods.html#static-knex)). The knex instance can be passed to [query](/api/model/static-methods.html#static-query), [$query](/api/model/instance-methods.html#query), and [$relatedQuery](/api/model/instance-methods.html#relatedquery) methods as the last argument. This pattern forces you to design your services and helper methods in a way that you always need to pass in a knex instance. A great thing about this is that you can pass a transaction object instead. (the knex/objection transaction object is a query builder just like the normal knex instance). This gives you a fine grained control over your transactions. +Another option is to add the knex instance to the request using a middleware and not bind models at all (not even using [Model.knex()](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-knex)). The knex instance can be passed to [query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-query), [$query](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#query), and [$relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#relatedquery) methods as the last argument. This pattern forces you to design your services and helper methods in a way that you always need to pass in a knex instance. A great thing about this is that you can pass a transaction object instead. (the knex/objection transaction object is a query builder just like the normal knex instance). This gives you a fine grained control over your transactions. ```js diff --git a/doc/recipes/paging.md b/doc/recipes/paging.md index befc7edf7..089d25540 100644 --- a/doc/recipes/paging.md +++ b/doc/recipes/paging.md @@ -1,6 +1,6 @@ # Paging -Most of the queries can be paged using the [page](/api/query-builder/other-methods.html#page) or [range](/api/query-builder/other-methods.html#range) method. +Most of the queries can be paged using the [page](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#page) or [range](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#range) method. ```js const result = await Person @@ -12,9 +12,9 @@ console.log(result.results.length); // --> 100 console.log(result.total); // --> 3341 ``` -There are some cases where [page](/api/query-builder/other-methods.html#page) and [range](/api/query-builder/other-methods.html#range) don't work. +There are some cases where [page](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#page) and [range](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#range) don't work. -1. In [modifyEager](/api/query-builder/other-methods.html#modifyeager) or named filters: +1. In [modifyEager](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/other-methods.md#modifyeager) or named filters: ```js // This doesn't work because the query `qb` fetches the diff --git a/doc/recipes/precedence-and-parentheses.md b/doc/recipes/precedence-and-parentheses.md index f21759b19..435dd379f 100644 --- a/doc/recipes/precedence-and-parentheses.md +++ b/doc/recipes/precedence-and-parentheses.md @@ -1,6 +1,6 @@ # Precedence and parentheses -You can add parentheses to queries by passing a function to any of the the [where*](/api/query-builder/find-methods.html#where) methods. +You can add parentheses to queries by passing a function to any of the the [where*](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#where) methods. ```js await Person diff --git a/doc/recipes/raw-queries.md b/doc/recipes/raw-queries.md index 9d7a871d2..c768dbd7d 100644 --- a/doc/recipes/raw-queries.md +++ b/doc/recipes/raw-queries.md @@ -1,10 +1,10 @@ # Raw queries -To mix raw SQL with queries, use the [raw](/api/objection/#raw) function from the main module. [raw](/api/objection/#raw) works just like the [knex's raw method](http://knexjs.org/#Raw) but in addition, supports objection queries, [raw](/api/objection/#raw), [ref](/api/objection/#ref), [lit](/api/objection/#lit) and all other objection types. You can also use [knex.raw()](http://knexjs.org/#Raw). +To mix raw SQL with queries, use the [raw](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#raw) function from the main module. [raw](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#raw) works just like the [knex's raw method](http://knexjs.org/#Raw) but in addition, supports objection queries, [raw](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#raw), [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#ref), [lit](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#lit) and all other objection types. You can also use [knex.raw()](http://knexjs.org/#Raw). -[raw](/api/objection/#raw) is handy when you want to mix SQL in objection queries, but if you want to fire off a completely custom query, you need to use [knex.raw](http://knexjs.org/#Raw). +[raw](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#raw) is handy when you want to mix SQL in objection queries, but if you want to fire off a completely custom query, you need to use [knex.raw](http://knexjs.org/#Raw). -There are also some helper methods such as [whereRaw](/api/query-builder/find-methods.html#whereraw) and [selectRaw](/api/query-builder/find-methods.html#selectraw) in the [QueryBuilder](/api/query-builder/). +There are also some helper methods such as [whereRaw](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#whereraw) and [selectRaw](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#selectraw) in the [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/). ## Examples @@ -40,7 +40,7 @@ const childAgeSums = await Person console.log(childAgeSums[0].childAgeSum); ``` -Binding arguments can be other [raw](/api/objection/#raw) instances, [QueryBuilders](/api/query-builder/) or pretty much anything you can think of. +Binding arguments can be other [raw](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#raw) instances, [QueryBuilders](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) or pretty much anything you can think of. ```js const { raw, ref } = require('objection'); diff --git a/doc/recipes/relation-subqueries.md b/doc/recipes/relation-subqueries.md index 82f0f228f..6a95ff568 100644 --- a/doc/recipes/relation-subqueries.md +++ b/doc/recipes/relation-subqueries.md @@ -1,6 +1,6 @@ # Relation subqueries -Let's say you have a `Tweet` model and a `Like` model. `Tweet` has a `HasManyRelation` named `likes` to `Like` table. Now let's assume you'd like to fetch a list of `Tweet`s and get the number of likes for each of them without fetching the actual `Like` rows. This cannot be easily achieved using `eager` because of the way the queries are optimized (you can read more [here](/api/query-builder/eager-methods.html#eager)). You can leverage SQL's subqueries and the [relatedQuery](/api/model/static-methods.html#static-relatedquery) helper: +Let's say you have a `Tweet` model and a `Like` model. `Tweet` has a `HasManyRelation` named `likes` to `Like` table. Now let's assume you'd like to fetch a list of `Tweet`s and get the number of likes for each of them without fetching the actual `Like` rows. This cannot be easily achieved using `eager` because of the way the queries are optimized (you can read more [here](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/eager-methods.md#eager)). You can leverage SQL's subqueries and the [relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-relatedquery) helper: ```js const tweets = await Tweet @@ -24,7 +24,7 @@ select "Tweet".*, ( from "Tweet" ``` -Naturally you can add as many subquery selects as you like. For example you could also get the count of retweets in the same query. [relatedQuery](/api/model/static-methods.html#relatedquery) method works with all relations and not just `HasManyRelation`. +Naturally you can add as many subquery selects as you like. For example you could also get the count of retweets in the same query. [relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#relatedquery) method works with all relations and not just `HasManyRelation`. Another common use case for subqueries is selecting `Tweet`s that have one or more likes. That could also be achieved using joins, but it's often simpler to use a subquery. There should be no performance difference between the two methods on modern database engines. diff --git a/doc/recipes/returning-tricks.md b/doc/recipes/returning-tricks.md index 41c4704d3..40ddeafaf 100644 --- a/doc/recipes/returning-tricks.md +++ b/doc/recipes/returning-tricks.md @@ -1,6 +1,6 @@ # PostgreSQL "returning" tricks -Because PostgreSQL (and some others) support [returning('*')](/api/query-builder/find-methods.html#returning) chaining, you can actually `insert` a row, or `update` / `patch` / `delete` existing rows, __and__ receive the affected rows as Model instances in a single query, thus improving efficiency. See the examples for more clarity. +Because PostgreSQL (and some others) support [returning('*')](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/find-methods.md#returning) chaining, you can actually `insert` a row, or `update` / `patch` / `delete` existing rows, __and__ receive the affected rows as Model instances in a single query, thus improving efficiency. See the examples for more clarity. # Examples diff --git a/doc/recipes/snake-case-to-camel-case-conversion.md b/doc/recipes/snake-case-to-camel-case-conversion.md index 84c6b556e..03893a0e2 100644 --- a/doc/recipes/snake-case-to-camel-case-conversion.md +++ b/doc/recipes/snake-case-to-camel-case-conversion.md @@ -2,9 +2,9 @@ You may want to use snake_cased names in database and camelCased names in code. There are two ways to achieve this: -1. _Conversion in knex using [knexSnakeCaseMappers](/api/objection/#knexsnakecasemappers)_. When the conversion is done on knex level __everything__ is converted to camel case including properties and identifiers in [relationMappings](/api/model/static-properties.html#static-relationmappings) and queries. When this method is used, objection has no idea the database is defined in snake case. All it ever sees is camel cased properties, identifiers and tables. This is because the conversion is done using knex's `postProcessResponse` and `wrapIdentifier` hooks which are executed by knex before objection receives the data. +1. _Conversion in knex using [knexSnakeCaseMappers](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#knexsnakecasemappers)_. When the conversion is done on knex level __everything__ is converted to camel case including properties and identifiers in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) and queries. When this method is used, objection has no idea the database is defined in snake case. All it ever sees is camel cased properties, identifiers and tables. This is because the conversion is done using knex's `postProcessResponse` and `wrapIdentifier` hooks which are executed by knex before objection receives the data. -2. _Conversion in objection using [snakeCaseMappers](/api/objection/#snakecasemappers)_. When the conversion is done on objection level only database columns of the returned rows (model instances) are convered to camel case. You still need to use snake case in [relationMappings](/api/model/static-properties.html#static-relationmappings) and queries. Note that [insert](/api/query-builder/mutate-methods.html#insert), [patch](/api/query-builder/mutate-methods.html#patch), [update](/api/query-builder/mutate-methods.html#update) and their variants still take objects in camel case. The reasoning is that objects passed to those methods usually come from the client that also uses camel case. +2. _Conversion in objection using [snakeCaseMappers](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection/#snakecasemappers)_. When the conversion is done on objection level only database columns of the returned rows (model instances) are convered to camel case. You still need to use snake case in [relationMappings](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-properties.md#static-relationmappings) and queries. Note that [insert](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#insert), [patch](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#patch), [update](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/mutate-methods.md#update) and their variants still take objects in camel case. The reasoning is that objects passed to those methods usually come from the client that also uses camel case. Let's assume this is our schema: diff --git a/doc/recipes/subqueries.md b/doc/recipes/subqueries.md index e65247cff..c3a4cf39f 100644 --- a/doc/recipes/subqueries.md +++ b/doc/recipes/subqueries.md @@ -1,6 +1,6 @@ # Subqueries -Subqueries can be written just like in knex: by passing a function in place of a value. A bunch of query building methods accept a function. See the knex.js documentation or just try it out. A function is accepted in most places you would expect. You can also pass [QueryBuilder](/api/query-builder/) instances or knex queries instead of functions. +Subqueries can be written just like in knex: by passing a function in place of a value. A bunch of query building methods accept a function. See the knex.js documentation or just try it out. A function is accepted in most places you would expect. You can also pass [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/) instances or knex queries instead of functions. Using a function: @@ -14,7 +14,7 @@ const peopleOlderThanAverage = await Person console.log(peopleOlderThanAverage); ``` -Using a [QueryBuilder](/api/query-builder/): +Using a [QueryBuilder](https://github.com/Vincit/objection.js/tree/v1/doc/api/query-builder/): ```js const peopleOlderThanAverage = await Person @@ -24,7 +24,7 @@ const peopleOlderThanAverage = await Person console.log(peopleOlderThanAverage); ``` -You can use [ref](/api/objection.js#ref) to reference the parent query in subqueries: +You can use [ref](https://github.com/Vincit/objection.js/tree/v1/doc/api/objection.js#ref) to reference the parent query in subqueries: ```js const { ref } = require('objection'); @@ -39,7 +39,7 @@ const peopleWithPetCount = await Person console.log(peopleWithPetCount[4].petCount); ``` -The above query can also be written using the [relatedQuery](/api/model/static-methods.html#static-relatedquery) (assuming a relation `pets` has been defined for `Person`): +The above query can also be written using the [relatedQuery](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/static-methods.md#static-relatedquery) (assuming a relation `pets` has been defined for `Person`): ```js diff --git a/doc/recipes/timestamps.md b/doc/recipes/timestamps.md index 6f9ca3034..435e4a1c4 100644 --- a/doc/recipes/timestamps.md +++ b/doc/recipes/timestamps.md @@ -1,6 +1,6 @@ # Timestamps -You can implement the [$beforeInsert](/api/model/instance-methods.html#beforeinsert) and [$beforeUpdate](/api/model/instance-methods.html#beforeupdate) methods to set the timestamps. If you want to do this for all your models, you can simply create common base class that implements these methods. +You can implement the [$beforeInsert](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforeinsert) and [$beforeUpdate](https://github.com/Vincit/objection.js/tree/v1/doc/api/model/instance-methods.md#beforeupdate) methods to set the timestamps. If you want to do this for all your models, you can simply create common base class that implements these methods. ```js class Person extends Model { diff --git a/replace-v1-links.js b/replace-v1-links.js new file mode 100644 index 000000000..54caba332 --- /dev/null +++ b/replace-v1-links.js @@ -0,0 +1,41 @@ +const { readdirSync, statSync, readFileSync, writeFileSync } = require('fs'); +const path = require('path'); + +walkNonAbsoluteLinks('./doc', link => { + link = link.replace('.html', '.md'); + return `https://github.com/Vincit/objection.js/tree/v1/doc${link}`; +}); + +function walkNonAbsoluteLinks(dir, callback) { + walkLinks(dir, link => { + if (link.startsWith('/')) { + return callback(link); + } else { + return link; + } + }); +} + +function walkLinks(dir, callback) { + walkFiles(dir, filePath => { + const fileData = readFileSync(filePath).toString(); + + const replacedData = fileData.replace(/\[([^\]]+)\]\(([^\)]+)\)/g, (_, text, link) => { + return `[${text}](${callback(link)})`; + }); + + writeFileSync(filePath, replacedData); + }); +} + +function walkFiles(dir, callback) { + for (const file of readdirSync(dir)) { + const filePath = path.join(dir, file); + + if (statSync(filePath).isDirectory()) { + walkFiles(filePath, callback); + } else if (file.endsWith('.md')) { + callback(filePath); + } + } +} From 06d3e86667c79b18352f0940688b8cf948c9be58 Mon Sep 17 00:00:00 2001 From: Shouvik Roy Date: Thu, 28 Nov 2019 11:59:38 +0530 Subject: [PATCH 29/30] fix:1572 incorrect type inference on insert --- typings/objection/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/typings/objection/index.d.ts b/typings/objection/index.d.ts index 4e07e790e..d81498cbb 100644 --- a/typings/objection/index.d.ts +++ b/typings/objection/index.d.ts @@ -683,9 +683,9 @@ declare namespace Objection { } interface Insert { - (modelsOrObjects?: Partial[]): QueryBuilder; - (modelOrObject?: Partial): QueryBuilder; - (): this; + (modelsOrObjects: Partial[]): QueryBuilder; + (modelOrObject: Partial): QueryBuilder; + (): QueryBuilder; } interface InsertGraph { From 5044910df98dff1e6e007e6fc8c452b0e6358996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Mon, 2 Dec 2019 10:22:12 +0200 Subject: [PATCH 30/30] fixes #1578 --- tests/ts/examples.ts | 8 ++++++++ typings/objection/index.d.ts | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/tests/ts/examples.ts b/tests/ts/examples.ts index c92f5965f..8f381bb68 100644 --- a/tests/ts/examples.ts +++ b/tests/ts/examples.ts @@ -219,6 +219,14 @@ async () => { ); }; +async () => { + const persons = await Person.query() + .joinRelation('children.children.pets') + .select('children:children:pets.*') + + takesPeople(persons) +} + // .query().castTo() async () => { const animals = await Person.query() diff --git a/typings/objection/index.d.ts b/typings/objection/index.d.ts index d81498cbb..1a22fedc2 100644 --- a/typings/objection/index.d.ts +++ b/typings/objection/index.d.ts @@ -346,8 +346,8 @@ declare namespace Objection { alias: boolean | string; } - interface JoinRelation { - (expr: RelationExpression, opt?: RelationOptions): QueryBuilder; + interface JoinRelation { + (expr: RelationExpression, opt?: RelationOptions): QB; } type JsonObjectOrFieldExpression = object | object[] | FieldExpression; @@ -780,14 +780,14 @@ declare namespace Objection { // TODO: fromJS does not exist in current knex documentation: http://knexjs.org/#Builder-fromJS withSchema(schemaName: string): this; - joinRelation: JoinRelation; - innerJoinRelation: JoinRelation; - outerJoinRelation: JoinRelation; - leftJoinRelation: JoinRelation; - leftOuterJoinRelation: JoinRelation; - rightJoinRelation: JoinRelation; - rightOuterJoinRelation: JoinRelation; - fullOuterJoinRelation: JoinRelation; + joinRelation: JoinRelation; + innerJoinRelation: JoinRelation; + outerJoinRelation: JoinRelation; + leftJoinRelation: JoinRelation; + leftOuterJoinRelation: JoinRelation; + rightJoinRelation: JoinRelation; + rightOuterJoinRelation: JoinRelation; + fullOuterJoinRelation: JoinRelation; // TODO: avgDistinct does not exist in current knex documentation: http://knexjs.org/#Builder-fromJS // TODO: modify does not exist in current knex documentation: http://knexjs.org/#Builder-modify