Hi all,
I’m having problems with the following relationship, can anybody help
me out here? I’m using Rails 2.1.
Cheers, Sazima
Table name: votes
Field Type Null Default
id int(11) No auto_increment
voter_id int(11) No
voted_id int(11) No
type int(11) No 0
value varchar(255) Yes NULL
status int(11) Yes 0
created_at datetime Yes NULL
updated_at datetime Yes NULL
class Vote < ActiveRecord::Base
belongs_to :voter, :class_name => :user, :foreign_key => :voter_id
belongs_to :voted, :class_name => :user, :foreign_key => :voted_id
end
Table name: users
id :integer(11) not null, primary key
login :string(255)
crypted_password :string(40)
salt :string(40)
created_at :datetime
updated_at :datetime
class User < ActiveRecord::Base
Votes
has_many :votes_made, :class_name => :vote, :foreign_key
=> :voter_id
has_many :votes_received, :class_name => :vote, :foreign_key
=> :voted_id
has_many :votees, :through => :votes_made, :source => :user, :uniq
=> true
has_many :voters, :through => :votes_received, :source
=> :user, :uniq => true
end