I have 2 models: Purchase and User. User has_many :purchases, and Purchase belongs_to :user. I want to select the following:
How many distinct users have made a purchase in the last 3 months, and also a way to print their email addresses (‘Purchase’ has a created_at field) (I want to just do this using the console). I’m a little confused as to how to go about it from a ruby perspective (I could do the straight SQL query, but I’d like to figure out how to do it in Ruby).
1 Answer