In my app that I am building to learn rails (RAILS 5), I have following end result I try to get in place:
I want users to be able to tag content of a PDF (attached to either an annotation record or a document record). After the annotation or document that the PDF is attached to has been classified by document type (e.g. PO, delivery note, etc.). A tag, when added, is associated with a predefined list of tag types (matching the document type of the annotation respectively of the document with the document type of the tag type). When adding the tag, I want to capture the content tagged (e.g. PO number or orderer name) and the coordinates in the PDF.
First part of the question
2 objects (classes / models) Annotation and Document have a 1-to-many relationship with the object (class / model) Tag (similar to order to order_item):
has_many :tags, dependent: :destroy
The model Tag has a 1-to-1 relationship with the model TagType:
belongs_to :annotation, :document
One single Tag-record however, can only belong to one Annotation / Document and needs to be deleted when the respective Annotation / Document gets deleted (I set dependent: :destroy
for that).
So, which type of association to use for Tag with TagType? has_one
? has_many
? belongs_to_
...?
Second part of the question:
Now, when adding a Tag to an Annotation or Document, the Tag will ge_ extracted text, coordinates and a needs to be assigned to a TagType. However, some tag types (for the document type of the annotation or document) can only be used once for an annotation / document - depending on the tag_type field "multiple occurrence" is false. How / where do I set this (validation / filter) up in the association?
And how to reduce the list depending on the tags in place (dynamically)?
All suggestions / directions welcome!