Skip to content

Instantly share code, notes, and snippets.

@mcculloughsean
Created June 28, 2010 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcculloughsean/456450 to your computer and use it in GitHub Desktop.
Save mcculloughsean/456450 to your computer and use it in GitHub Desktop.
#Find all the location records by that advertiser
location_records_for_advertiser = Locations.find_by_advertiser_id(@advertiser.id)
#make an array of just IDs
location_ids = location_records_for_advertiser.collect { |l| l.id }
#Find all the placement records by the location ids
placements_for_advertiser = Placements.find(:all, :conditions => {:location_id => location_ids})
#make another array of just ids
placement_ids = placements_for_advertiser.collect { |p| p.id }
pushed_count = PushedDeal.find(:all, :conditions => {:placement_id => placement_ids}).length
impressed_count = EngagedDeal.find(:all, :conditions => {:placement_id => placement_ids}).length
engaged_count = ImpressedDeal.find(:all, :conditions => {:placement_id => placement_ids}).length
@total_delivered = pushed_count + impressed_count + engaged_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment