I have a User model that has a meta column with a hash, for example {“version”=>”1.0”, “country”=>”UK”}
What is the best practice / efficient way to count each individual values in any key? So I might want to figure out how many records have country = UK or USA or France, etc. I do not know all the possible values in each key beforehand…
I guess I can do it in a big loop
User.all.each do |user|
user.meta["country"] ..........
but is there a better way to do it?
Yes, there’s
group_by