In Ruby-on-Rails, this is called a "polymorphic association."
I have a few Commentable things in my application, tables for each below:
Post id | title | text | author (FK:Person.id) | ... Person id | name | ... Photo id | title | owner (FK:Person.id) | path | ...
I would like to add a Comments table as follows:
Comments id | commentable_type | commentable_id | text | author (FK:Person.id)
I understand that I have lost the referential integrity of the database this way, but the only option is to have several Comments : PostComments , PersonComments , PhotoComments , ... tables
And now for the question:
How can I create a form that will check how to perform a search by first getting the table name from Comments.commentable_type and then the identifier from Comments.commentable_id ?
source share