objection-unique icon indicating copy to clipboard operation
objection-unique copied to clipboard

Doesn't work with graph inserts?

Open tsongas opened this issue 5 years ago • 1 comments

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?

tsongas avatar Mar 13 '19 06:03 tsongas

This is a known limitation. We're planning to resolve this issue but pull requests are welcome too.

Thank you for using objection-unique!

joaonice avatar Apr 05 '19 22:04 joaonice