Caveat: I am using the ActiveUUID gem instead of using auto-incrementing keys. So this issue may be related to that if you are unable to reproduce.
Because of the way we do change data capture all tables in our database require a primary_key. Even though mapping tables only do insert/delete we still want to track if a user has ever had certain permissions.
In the method:
def add(relation, role)
relation.role_ids |= [role.id]
end
It doesn't appear to generate the primary_key on creation of the record.
I also tried...
def add(relation, role)
relation.roles << role
end
However, it results in the same issue for me.
If this is indeed related to ActiveUUID I apologize.