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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are there plans for a dedicated invitation model? #888

Open
christianrolle opened this issue Apr 21, 2023 · 1 comment
Open

Are there plans for a dedicated invitation model? #888

christianrolle opened this issue Apr 21, 2023 · 1 comment

Comments

@christianrolle
Copy link

christianrolle commented Apr 21, 2023

Hey 馃槃
I tried to move the invitation into a dedicated Invitation model. Main reason for that attempt was that most users never are invited. So why having those extra attributes for them? And furthermore it feels natural. Like User has one invitation.
However I simply delegated the attributes to the dedicated Invitation model, like:

class User < ApplicationRecord
  has_one :invitation

  delegate :user_invitation_token, to: :invitation, allow_nil: true
  delegate :user_invitation_created_at, :invitation_created_at=, to: :invitation, allow_nil: true
  delegate :user_invitation_sent_at, :invitation_sent_at=, to: :invitation, allow_nil: true
  delegate :user_invitation_accepted_at, :invitation_accepted_at=, to: :invitation, allow_nil: true

  def user_invitation
    invitation || build_invitation
  end
end

class Invitation < ApplicationRecord
  belongs_to :user
end

But had to stop because finding a user by its invitation token heavily relies on the Devise#find_or_initialize_with_error_by
which I obviously don't wanna screw up.
So I think it is currently not easy to extract the invitation into a dedicated model.
My question: Are there plans in regards to this? Does it make sense from your side?

@scambra
Copy link
Owner

scambra commented Apr 21, 2023

I'm open to change to independent model, with own table, with a polymorphic belongs_to to support adding invitable to multiple models. However, it isn't simple task, and I don't have plans to do it shortly. If someone sends a PR I will review it to merge it, or I could help with the change, but I don't have much time

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

No branches or pull requests

2 participants