Skip to content

Instantly share code, notes, and snippets.

@Breefield
Created November 22, 2013 20:37
Show Gist options
  • Save Breefield/7606431 to your computer and use it in GitHub Desktop.
Save Breefield/7606431 to your computer and use it in GitHub Desktop.
Location.near('San Francisco', 50)
.where(located_type: 'Event') # Filter other polymorphic models out
.joins(:event) # ...JOIN events ON...
.where('events.price <= ?', 20) # Filter events by their price
.includes(:event) # Avoid N+1
.reorder('events.price ASC, distance ASC')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment