This page demonstrates the methods that allow you to create a role or a relationship (or all together) or completely destroy a relationship and role together.

That's exactly it annoying:

Destroying the connection and the role itself

Banal example:

There is the role of "admin" and N users. Dole several users the role of "admin":

user = User.find(1) # IDs: 1, 2, 3, 4, 5... user.add_role :admin 

This method will add a link to the users_roles table.

After some time, it was necessary to remove the "admin" role from one of the users. According to the link above, we are boldly showing:

 user = User.find(1) user.remove_role :admin 

But only this method will remove the role itself and all connections with other users.

How to be?

  • show the log of the moment of the role deletion or add a minimal reproducible example to the question - Mikhail Vaysman
  • He quickly went over the code, found only one circumstance when this could happen: if it was the last user with this role . And it is disabled . Fits the conditions of your experiment? :) - D-side
  • @ D-side before posting a question, and walked through the scenario when the role is already taken by other users. Well, I wrote this in the penultimate paragraph :) I actually reproduced all the situations. The role itself and all connections with all users were always removed. This is strange, yes. If only because the author of gem has thought about it anyway. But I describe the situation on the Devise, Rolify and Pundit boxed bundle. - Colibri
  • And fill this box bundle with a githab, for example. Because from the documentation for Rolify, the behavior that you describe does not follow at all. - D-side
  • @ D-side I can’t fill the whole project :) But the only thing I did in that bundle was the installation steps for each gem. In the settings they did not climb. - Colibri

0