In development on sqlite this works a charm:
@human = Human.joins(:human_logins).group("human_logins.human_id").order("count(human_logins.human_id) ASC")
Though, in production on Heroku and using PG, it crashes and I get the following error:
ActionView::Template::Error (PG::GroupingError: ERROR: column "humans.id" must appear in the GROUP BY clause or be used in an aggregate function
Guessing it's just a compatibility problem, any insight on how I can alter this so that it works nicely in production would be awesome.