Ich habe diese VerbändeAktive Rekord: Gruppenergebnisse mit einbezogen Vereinigungen
class Application (id, priority, registration_id, uni_id)
belongs_to :registration
belongs_to :uni
end
class Uni (id, name)
has_many :applications
end
class Registration (id, fname, lname, total_points)
has_many :applications, :dependent => :destroy
has_many :unis, :through => :applications
end
Jetzt laufe ich Abfrage wie
@registration = Registration.includes(:applications, :unis).where('applications.priority = ?', true).references(:applications).order(total_points: :desc)
Bisher funktioniert es in Ordnung. Dies gibt die Anmeldungen, die
1. application priority true and
2. order the registrations by total_points.
Jetzt habe ich die Registrierungen erhalten möchten, die
1. application priority true
2. order the registrations by total_points
3. group the registrations by uni id.
Zum Beispiel haben die Registrierungen von uni-ID 1, in einer Gruppe sein sollte und sollte von total_points bestellt werden, Ähnlich sollten Registrierungen für uni id 2 in der zweiten Gruppe sein und sollten von total_points und so weiter angeordnet werden. Ich habe versucht, so etwas wie dies unter
@registration = Registration.includes(:applications, :unis).where('applications.priority = ?', true).references(:applications).group('unis.id').order(total_points: :desc)
zu tun, aber das gibt mir nicht, was ich will. Wie sollte ich meine Abfrage ändern, um das erwartete Ergebnis zu erhalten?