I am doing a coding project in rails. I have a user model, and I want to add a "spouse_id" to it (which would reference other users). Can a model reference itself in a foreign key?
-
What is the data store, for those of us not familiar with Rails? In some data stores, joins of any kind are problematic, and Rails is not the issue.– Robert HarveyJul 24, 2015 at 14:39
-
I'm not sure what you mean, but I am storing the data in a database (sqlite3 in dev; postgres in prod)– JeffJul 24, 2015 at 14:40
-
2Then the answer is "of course." It's called a self-join.– Robert HarveyJul 24, 2015 at 14:40
-
1Thanks @RobertHarvey, I'm still new at this, never heard of a self-join. Now that I know what to look for: railscasts.com/episodes/163-self-referential-association– JeffJul 24, 2015 at 14:41
-
2Also called a Self-referencing table.– Robert HarveyJul 24, 2015 at 14:42