Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for polymorphic User associations #570

Open
ajclaasen opened this issue Nov 24, 2021 · 0 comments · May be fixed by #571
Open

Add support for polymorphic User associations #570

ajclaasen opened this issue Nov 24, 2021 · 0 comments · May be fixed by #571

Comments

@ajclaasen
Copy link

ajclaasen commented Nov 24, 2021

Hello & thank you for all of your work! Rolify has been amazing to work with!

For a project, I need to be able to assign Roles to both Users and Invitations. My first guess would be to use a polymorphic association in the join table between them, allowing it to accept either Users or Invitations.

I did a little research into/with the source code, and it seems that this is currently not possible due to the has_and_belongs_to_many in the rolify method, which doesn't support polymorphism. Changing it to a has_many :through would be a great step in the direction of supporting polymorphism on the User side. Just for reference, #411 and #318 are related to this proposed change, with a pending PR at #181.

If I understand correctly, I also need to pass an as: parameter to the has_many :join_table in the rolify method, so that rolified models know that they are polymorphic and can set the :roleable_type in the join table.

Thanks again for all the work, it's been a blast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant