Skip to content

Commit

Permalink
Merge pull request #27 from seegno/bugfix/fix-get-knex-when-not-in-model
Browse files Browse the repository at this point in the history
Fix knex getter when undefined on model class
  • Loading branch information
joaonice authored May 15, 2020
2 parents 8713e82 + 9a2b9a3 commit 1812934
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = options => {
$beforeInsert(context) {
const parent = super.$beforeInsert(context);

return this.queryResolver(parent);
return this.queryResolver(parent, false, {}, context);
}

/**
Expand All @@ -46,16 +46,16 @@ module.exports = options => {
throw new Error('Unique validation at update only works with queries started with $query.');
}

return this.queryResolver(parent, true, queryOptions);
return this.queryResolver(parent, true, queryOptions, context);
}

/**
* Query resolver.
*/

queryResolver(parent, update = false, queryOptions = {}) {
queryResolver(parent, update = false, queryOptions = {}, context) {
return Promise.resolve(parent)
.then(() => Promise.all(this.getQuery(update, queryOptions)))
.then(() => Promise.all(this.getQuery(update, queryOptions, context)))
.then(rows => {
const errors = this.parseErrors(rows);

Expand All @@ -73,9 +73,9 @@ module.exports = options => {
* Get select query.
*/

getQuery(update, queryOptions) {
getQuery(update, queryOptions, context) {
return options.fields.reduce((queries, field, index) => {
const knex = Model.knex();
const knex = Model.knex() || context.transaction;
const collection = knex(this.constructor.tableName);
const fields = castArray(field);

Expand Down

0 comments on commit 1812934

Please sign in to comment.