I have a Rails model which I use two has_one
relations: requester
and friend
. When in the console I use:
f = FriendRequest.all
f[0].requester
I get ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: users.requester_id: SELECT "users".* FROM "users" WHERE "users"."requester_id" = 4 LIMIT 1
.
I don't really know how to specify a `has_one' relationship with a class name and a key which specifies the record. This is my model:
class FriendRequest < ActiveRecord::Base
has_one :requester, :class_name => "User", :foreign_key => "requester_id"
has_one :friend, :class_name => "User", :foreign_key => "friend_id"
end
How could I do it? In a belongs_to
relationship I use the same, obviously replacing has_one
with belongs_to
. Thanks!