table linking questions

I'm about to try coding a quick test app as my first rails test.

My first question should be quick. how do I include two ids in the same table. for example relating two people together.


For your first question, the second person_id could be called parent_id, stating that that person is the parent of the parent / child relationship. For your second question, you should look into polymorphic relationships. You can read more about them here:

I hope this helps.


Jack720 wrote:

actually on the first question it couldn't be parent_id because the relationship would depend on the type. sometimes a parent/child sometimes a spouse/child or maybe an adoption. etc. I thought rails picked up relationships based on convention so i wanted to tie both fields to the same table. I guess I wanted to know the convention for that.

I'll look into polymorphic relationships Thank you.