I have a simple referral system composed of Users and Referrals.
The users table has an id value, of course. The referrals table has
referer_id and referee_id. The relationships are set up as follows:
class User < ActiveRecord::Base
has_many :referrals,
:foreign_key => "referer_id"
has_one :referer,
:through => :referrals,
:source => :referer
has_many :referees,
:through => :referrals,
:source => :referee
class Referral < ActiveRecord::Base
belongs_to :referer,
:class_name => :user,
:foreign_key => "referer_id"
belongs_to :referee,
:class_name => :user,
:foreign_key => "referee_id"
Most of this works. User.referrals returns all the referral objects.
Referral.referer and Referral.referee both return the appropriate
objects. But the User.referer/referee methods both raise the same
error:
>> user.referer
TypeError: can't convert Symbol into String
I would like User.referer to return the single user object that is their
referer. And User.referees would return an array of user objects that
were refered. What am I doing wrong here?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---