Hi All,
I’m building an app that needs to make a comparison between two people
and I’m wondering how to best build the models, and if I’m doing this
correctly.
I’m representing each partner as a User, so I wanted to keep just a user
table and a comparisons table (the comparisons table will keep all the
comparison data, the user model will hold all the data about that
individual user)
I’m thinking of making a User-to-User self-referential join through a
“comparison” model.
So, I’d have two models: the user model, and a comparison model
The user model would look something like this:
class User < ActiveRecord::Base
belongs_to :partner, :through => :comparisons
end
and the comparisons:
class Comparison < ActiveRecord::Base
belongs_to :user
has_one :partner, :class_name => “User”, :foreign_key => “partner_id”
end
I honestly have no idea if this will work… does this look close?
Thanks in advance!
Dustin