我尝试使用 habtm 关系,但我需要使用 uid 作为外键
SELECT "friends".* FROM "friends" INNER JOIN "friendships" ON "friends"."uid" = "friendships"."uid" WHERE "friendships"."user_id" = 4
#User
has_and_belongs_to_many :friends, :class_name => "Friend", :join_table => "friendships", :association_foreign_key => "uid"
#Friend
has_and_belongs_to_many :users, :class_name => "User", :join_table => "friendships", :foreign_key => "uid"
SELECT "friends".* FROM "friends" INNER JOIN "friendships" ON "friends"."id" = "friendships"."uid" WHERE "friendships"."user_id" = 4