这就是我所拥有的:
class Membership < ApplicationRecord
belongs_to :user
belongs_to :group
end
class User < ApplicationRecord
has_one :user_score
has_many :memberships
has_and_belongs_to_many :groups, through: :memberships # an user can be owner or member of a group
end
class Group < ApplicationRecord
has_many :memberships
has_many :members, through: :memberships, source: :user
end
class UserScore < ApplicationRecord
belongs_to :user
end我想要做的是从按'total_score‘(这是UserScore的属性)排序的组中获取用户列表,但到目前为止我失败了。
发布于 2018-02-12 02:51:02
显然,我的机器上没有加载模式。所以,我的答案是
User.joins(:user_score, :groups).where(groups: {name: 'Name of your group'}).order('user_scores.total_score')https://stackoverflow.com/questions/48738809
复制相似问题