Check polymorphic type in validations
* Previously, some models had "duplicated" `belongs_to` associations, which were now removed (and replaced by the `include Creation`).
This commit is contained in:

committed by
Sebastian Serth

parent
be4f2b790d
commit
977fa4539e
@@ -4,11 +4,15 @@ module ContributorCreation
|
||||
extend ActiveSupport::Concern
|
||||
include Contributor
|
||||
|
||||
ALLOWED_CONTRIBUTOR_TYPES = [InternalUser, ExternalUser, ProgrammingGroup].map(&:to_s).freeze
|
||||
|
||||
included do
|
||||
belongs_to :contributor, polymorphic: true
|
||||
alias_method :user, :contributor
|
||||
alias_method :user=, :contributor=
|
||||
alias_method :author, :user
|
||||
alias_method :creator, :user
|
||||
|
||||
validates :contributor_type, inclusion: {in: ALLOWED_CONTRIBUTOR_TYPES}
|
||||
end
|
||||
end
|
||||
|
@@ -3,9 +3,13 @@
|
||||
module Creation
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
ALLOWED_USER_TYPES = [InternalUser, ExternalUser].map(&:to_s).freeze
|
||||
|
||||
included do
|
||||
belongs_to :user, polymorphic: true
|
||||
alias_method :author, :user
|
||||
alias_method :creator, :user
|
||||
|
||||
validates :user_type, inclusion: {in: ALLOWED_USER_TYPES}
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user