Skip to content

Add support for polymorphic User associations #570

@eboekhold

Description

@eboekhold

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions