class Annotation < ApplicationRecord acts_as_list column: :rank, scope: %i[doctrine_id] 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 has_many :annotation_annomarks, dependent: :destroy has_many :annomarks, through: :annotation_annomarks validates :content, presence: true 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 def citing_document_ids documents.map(&:id) end searchable do integer :document_id integer :doctrine_id join(:library_rank, target: Cdao::Document, type: :integer, join: { from: :id, to: :document_id }) join(:search_year, target: Cdao::Document, type: :integer, join: { from: :id, to: :document_id }) join(:search_doc_date, target: Cdao::Document, type: :date, join: { from: :id, to: :document_id }) date :created_at date :updated_at text :phil_rep string :phil_rep end end