Two or more nonNullable associations



I have the same problem as the person in this issue:

In the issue, author said he will handle it on his side, but I am clueless how can you handle this situation.

My code is somthing like this:

const r = new Rating()


But this fails with

Duplicate entry '691' for key 'PRIMARY'

Because it tries to save it multiple times, I guess. It is correctly saved in the database, but still throws this error.


How about?


await r.projectMonth().associate(projectMonth)
await r.projectRating().associate(projectRating)
await r.standup().associate(standup)


The problem here is that the database has these foreign keys as NOT NULL. So save will fail.

As far as I know, there are two options and I don’t like neither:

  1. make the columns nullable
  2. don’t use Lucid Models, but use Database directly

Isn’t there any better option?