Skip to content

Instantly share code, notes, and snippets.

@jraines
Created December 21, 2011 01:11
Show Gist options
  • Save jraines/1504084 to your computer and use it in GitHub Desktop.
Save jraines/1504084 to your computer and use it in GitHub Desktop.
# Hash for each brand.
# Each key is an item of that brand, in a format like 'id:type:name'.
# Each value is a json string representing an array of user ids.
# For this query we would:
# iterate over each brand
# pull the the keys that match our type ('*jeans*') and
# get the user ids array for each brand of jeans.
# Then something like this, where "brand" in this case is a constructed object
# from the above operation, with name and user_id_array_for_jeans:
results = {}
brands.each do |b|
jean_wearers = b.user_id_array_for_jeans
results[brand.name] = User.where(:id => jean_wearers).where(demographic_conditions).count
end
results.sort_by {|brand, count| count}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment