Skip to content

Instantly share code, notes, and snippets.

@etherealite
Created December 25, 2012 10:57
Show Gist options
  • Save etherealite/4372649 to your computer and use it in GitHub Desktop.
Save etherealite/4372649 to your computer and use it in GitHub Desktop.
Single query solution to finding nearest donees with matching timeslots
def donees_in_radius_with_timeslots(radius)
required_bits = 2**User.valid_roles.index(:donee)
Location.near(self.location,
radius,
:select => "locations.*, users.*, time_slots.*"
).joins(:user => :time_slots)
.where(["roles_mask & ? > 0", required_bits])
.where(["roles_mask & ? > 0", required_bits])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment