objection-unique
objection-unique copied to clipboard
Doesn't work with graph inserts?
I added objection-unique to my Users model to make user email addresses unique:
const unique = require('objection-unique')({
fields: ['email'],
identifiers: ['id']
});
However when I do a graph insert in my Account model as shown below to insert an account and related user, I get a database error due to the Postgres unique constraint, objection-unique doesn't seem to be doing anything:
static createAccount(firstName, lastName, email, password, trialEnds) {
return this.query().insertGraph({
trialEnds,
users: [
{
firstName,
lastName,
email,
password
}
]
});
}
Is this a known limitation of objection-unique that it doesn't work with graph inserts, or am I doing something wrong?
This is a known limitation. We're planning to resolve this issue but pull requests are welcome too.
Thank you for using objection-unique!