I have two models; User and Raffle. I also have a junction table with just an id, a user_id, and a raffle_id.
I then get the Raffles from the User model like this:
public function getRaffles()
{
return $this->hasMany(Raffle::class, ['id' => 'raffle_id'])
->viaTable('raffle_user', ['user_id' => 'id']);
}
And from the Raffles model like this:
public function getUsers()
{
return $this->hasMany(User::class, ['id' => 'user_id'])
->viaTable('raffle_user', ['raffle_id' => 'id']);
}
This works, and I can successfully call $user->link('raffles', $raffle); etc.
However, when I try to unlink a record like $user->unlink('raffles', $raffle); I get the error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'raffle_id' cannot be null
Am I doing something wrong, or do I have something misconfigured?