smartprix / xorm

NodeJS ORM based on ObjectionJS with some extra utilities
18 stars 4 forks source link

$afterUpdate should only run if any row is actually updated #16

Open parul157 opened 5 years ago

parul157 commented 5 years ago

Working example:

import knexUtils from '@smpx/knex-utils';
import {Model} from 'xorm';

const knex = knexUtils.getKnex();
Model.knex(knex);

class Category extends Model {
    async $afterUpdate(opts, queryContext) {
        console.log('update'); // this is run
        await super.$afterUpdate(opts, queryContext);
    }
}

async function test() {
    console.log(await Category.query().where('id', 999999).update({slug: 'abc'})); // prints 0, no rows were updated
}

test().catch((err) => {
    console.error(err);
});