lundi 13 août 2018

Writing an ActiveRecord/AREL query to select the coin held by the greatest numbers of users

Just to explain: I have a users model, and users have many portfolios. Each portfolio has many positions, and each position belongs to a coin. I want to select the coin that is held by the greatest number of users, but am struggling a bit to come up with the correct query. I could imagine writing something like 'find the coin that has the most positions, where the user_ids of the positions are distinct'. Is that the right idea, and how does type that up?

Aucun commentaire:

Enregistrer un commentaire