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?
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:
The class_name option should really be a string (ie :class_name =>
'User')
SELECT "users".* FROM "users" INNER JOIN referrals ON users.id =
referrals.referer_id WHERE (("referrals".referer_id = 1))
But it should be using WHERE referrals.referee_id = 1 instead of
referer_id = 1. I've tinkered with various permutations but cannot make
it query for users.id = referer_id WHERE referee_id = x. Any thoughts?
If referrals are all the referrals made by that user (since it uses
the referer_id foreign key) it seems to me that will never get you a
user's referer (unless the use referred themselves).
You'd want to go through the referrals table using the other key.