Browse Source

Implement multiple annomarks for annotations

pull/9/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
59af79f97d
  1. 2
      app/controllers/doctrine/annotations_controller.rb
  2. 3
      app/models/annomark.rb
  3. 6
      app/models/annotation.rb
  4. 7
      app/models/annotation_annomark.rb
  5. 5
      db/migrate/20220128044651_remove_annomark_id_in_annotations.rb
  6. 13
      db/migrate/20220128044720_create_annotation_annomarks.rb

2
app/controllers/doctrine/annotations_controller.rb

@ -49,6 +49,6 @@ class Doctrine::AnnotationsController < ApplicationController
private
def resource_params
params.permit(:document_id, :annomark_id, :phil_rep, :editor_notes, :rank)
params.permit(:document_id, :phil_rep, :editor_notes, :rank, annomark_ids: [])
end
end

3
app/models/annomark.rb

@ -4,5 +4,6 @@ class Annomark < ApplicationRecord
validates :name, :code, presence: true
validates :code, uniqueness: { scope: %i[name] }
has_many :annotations, dependent: :restrict_with_error
has_many :annotation_annomarks, dependent: :destroy
has_many :annotations, through: :annotation_annomarks
end

6
app/models/annotation.rb

@ -1,8 +1,6 @@
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
@ -10,8 +8,8 @@ class Annotation < ApplicationRecord
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] }
has_many :annotation_annomarks, dependent: :destroy
has_many :annomarks, through: :annotation_annomarks
def documents
annotation_documents.collect(&:document)

7
app/models/annotation_annomark.rb

@ -0,0 +1,7 @@
class AnnotationAnnomark < ApplicationRecord
belongs_to :annotation, optional: false
belongs_to :annomark, optional: false
validates :annomark_id, uniqueness: { scope: %i[annotation_id] }
end

5
db/migrate/20220128044651_remove_annomark_id_in_annotations.rb

@ -0,0 +1,5 @@
class RemoveAnnomarkIdInAnnotations < ActiveRecord::Migration[6.1]
def change
safety_assured { remove_column :annotations, :annomark_id, :integer, null: false }
end
end

13
db/migrate/20220128044720_create_annotation_annomarks.rb

@ -0,0 +1,13 @@
class CreateAnnotationAnnomarks < ActiveRecord::Migration[6.1]
def change
create_table :annotation_annomarks do |t|
t.references :annotation, null: false
t.references :annomark, null: false
t.timestamps
end
add_index :annotation_annomarks, %i[annotation_id annomark_id],
name: "index_annotation_annotation_marks_uniquness", unique: true
end
end
Loading…
Cancel
Save