I wish to build a simple application with 3 types of objects:
- Article (1st Day in RoR, Why PHP is still awesome, RoR vs. PHP)
- Author (Bob, Steve, Jen)
- Tags (RoR, PHP)
An author writes an article, and and make appropriate tags.
so:
author has many articles; article belongs to author
But what about tags? I want both articles and authors to have tags.
I can imagine that:
author has many tags; article has many tags
But what about the declaration on the tags model?
tag belongs to authors; tag belongs to articles
Will the two belongs_to interfere with each other?
What i fear is that tag will require both an author and article parent. and in the event where it has both types of parents, deleting one would delete the tag and the other parent due to foreign key constraints in the database.
Thanks in advance!
You are looking for polymorphyc associations: