module.exports = function(Self) { Self.validatesPresenceOf('observationTypeFk', { message: 'Observation type cannot be blank' }); Self.validateAsync('typeUnique', typeIsUnique, { message: 'Observation type must be unique' }); async function typeIsUnique(err, done) { let filter = { fields: ['id'], where: { observationTypeFk: this.observationTypeFk, addressFk: this.addressFk } }; if (this.id) filter.where.id = {neq: this.id}; if (await Self.findOne(filter)) err(); done(); } };