You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
799 B
29 lines
799 B
class Annotation < ApplicationRecord |
|
acts_as_list column: :rank, scope: %i[doctrine_id] |
|
|
|
belongs_to :annomark, optional: false |
|
|
|
belongs_to :doctrine, optional: false |
|
|
|
belongs_to :document, polymorphic: true, optional: false |
|
|
|
has_many :annotation_documents, inverse_of: :annotation, dependent: :destroy |
|
accepts_nested_attributes_for :annotation_documents, allow_destroy: true |
|
|
|
validates :annomark_id, |
|
uniqueness: { scope: %i[doctrine_id document_id document_type phil_rep] } |
|
|
|
def documents |
|
annotation_documents.collect(&:document) |
|
end |
|
|
|
def add_document(document) |
|
record = annotation_documents.new |
|
record.document = document |
|
record.save |
|
end |
|
|
|
def remove_document(document) |
|
annotation_documents.find_by(document_id: document.id).destroy |
|
end |
|
end
|
|
|