我与另一个表有两个has_many
关联:
has_many :sent_requests, foreign_key: :requester_id, class_name: 'FriendRequest'
has_many :pending_requests, foreign_key: :target_id, class_name: 'FriendRequest'
我想热切地加载这些关联,但includes
没有帮助。
以下是来自日志的请求:
SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
我接下来试过了:
joins("LEFT OUTER JOIN friend_requests as sent_requests
ON sent_requests.requester_id = users.id
LEFT OUTER JOIN friend_requests as pending_requests
ON pending_requests.target_id = users.id")
但这似乎并没有正确填补我的关联。我看到每个friend_request
有多个用户。
如何加载我的关联?