Skip to content

Commit

Permalink
Use invited_by_foreign_key settings from the model
Browse files Browse the repository at this point in the history
Fix usage of invited_by_class_name in required_fields method.
  • Loading branch information
scambra committed Oct 16, 2024
1 parent 5bfcc77 commit eba8e45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Use invited_by_class_name and invited_by_foreign_key settings from the model

## 2.0.9
- Do not accept expired invitation on password reset ([#897](https://github.com/scambra/devise_invitable/pull/897))

Expand Down
6 changes: 3 additions & 3 deletions lib/devise_invitable/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Invitable
else
{ polymorphic: true }
end
if fk = Devise.invited_by_foreign_key
if fk = invited_by_foreign_key
belongs_to_options[:foreign_key] = fk
end
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && self < ActiveRecord::Base
Expand Down Expand Up @@ -76,9 +76,9 @@ module Invitable

def self.required_fields(klass)
fields = [:invitation_token, :invitation_created_at, :invitation_sent_at, :invitation_accepted_at,
:invitation_limit, Devise.invited_by_foreign_key || :invited_by_id, :invited_by_type]
:invitation_limit, klass.invited_by_foreign_key || :invited_by_id, :invited_by_type]
fields << :invitations_count if defined?(ActiveRecord) && self < ActiveRecord::Base
fields -= [:invited_by_type] if invited_by_class_name
fields -= [:invited_by_type] if klass.invited_by_class_name
fields
end

Expand Down

0 comments on commit eba8e45

Please sign in to comment.