I'm trying to wrap my head around how to set up this schema with polymorphic associations:
a "Document" has one metadata object, but this can either be "PDFMetaData" or "TXTMetaData".
My concerns are:
To set up this association, I can do this
class Document
belongs_to :metadata, :polymorphic => true
end
class PDFMetaData
has_one :document, :as => :metadata
end
class TXTMetaData
has_one :document, :as => :metadata
end
This works, but it kind of feels like reverse for me: A document has_one metadata object, not opposite?
Also, I'm really running into problems when trying to create a nested form for my new document. I know I can use fields_for, but how do I know what kind of object it is? (PDFMetaData or TXTMetaData). Do I have to render separate partials depending on what kind of document I have?
I'm afraid that the latter ties in with my first question, and that I'm doing something terribly wrong.
Thanks