Hello all,
I''m sorry for the long question, but I can''t seem to figure
this out,
and I haven''t managed to find anything in the list archive.
I''m trying to represent a trust relationships between user.
It''s
essentially a weighted, directed graph where users are nodes and trust
ratings are edges. I have two (postgres) tables:
users (
id serial primary key,
. . .
);
ratings (
id serial primary key,
rater_id int references users(id) not null,
rated_id int references users(id) not null,
rating int(1) not null,
constraint no_self_rate check (rater_id <> rated_id)
);
The row (rater_id = i, rated_id = j, rating = true) represents the
statement "user i trusts user j" (and likewise for distrust).
My models currently look like:
class User < ActiveRecord::Base
has_many :ratings_out, :class_name => ''Rating'',
:foreign_key => ''rater_id''
has_many :ratings_in, :class_name => ''Rating'',
:foreign_key => ''rated_id''
end
class Rating < ActiveRecord::Base
belongs_to :rater, :class_name => ''User''
belongs_to :rated, :class_name => ''User''
end
When I use the rating controller scaffolding, it doesn''t show the
rater_id or rated_id columns at all.
I suspect that I''m not quite understanding the semantics of belongs_to.
Is there an accepted way to do this, or will it require some kind of
hack? It seems like a pretty straightforward situation.
Thanks so much for reading this.
Regards,
Jesse Tov