Say I have the two models Users
and Appointments
where a user has_many appointments.
An appointment can be of two different types: typeA
and typeB
.
How can I write a query to order the users by the amount of typeB
appointments they have?
I've looked into counter_cache but it seems to just count the number of the association (so in this case the number of appointments a user would have) and does not allow for the counting of a particular type of appointment.