Create new polymorphic model Document.
This commit is contained in:
8
app/models/concerns/documentable.rb
Normal file
8
app/models/concerns/documentable.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
module Documentable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_many :documents, as: :documentable, dependent: :destroy
|
||||
end
|
||||
|
||||
end
|
||||
9
app/models/document.rb
Normal file
9
app/models/document.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class Document < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :documentable, polymorphic: true
|
||||
|
||||
validates :user_id, presence: true
|
||||
validates :documentable_id, presence: true
|
||||
validates :documentable_type, presence: true
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user