Two or more nonNullable associations


#1

Hi,

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()
r.projectMonth().associate(projectMonth)
r.projectRating().associate(projectRating)
r.standup().associate(standup)

await r.save()

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.


#2

How about?

await r.save()

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

#3

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?