再次关联排序问题:)
我正试图弄清楚如何通过对总发送和接收挑战总量的反向关联来对具有许多挑战的用户进行排序。
这是关联代码:
class User < ActiveRecord::Model
has_many :sent_challenges, class_name: "Challenge", foreign_key: :challenger_id, inverse_of: :challenger
has_many :received_challenges, class_name: "Challenge", foreign_key: :opponent_id, inverse_of: :opponent
class << self
def in_order
# return users sorted by amount of sent + received challenges
order("…")
end
end
end
我希望.in_order
方法返回按总挑战排序的用户。