This is what I have:
class Membership < ApplicationRecord
class User < ApplicationRecord
has_and_belongs_to_many :groups, through: :memberships # an user can be owner or member of a group
class Group < ApplicationRecord
has_many :members, through: :memberships, source: :user
class UserScore < ApplicationRecord
What I'm trying to do is to get a list of users from a group ordered by 'total_score' (which is an attribute of UserScore) but I've failing so far.