Created
December 25, 2012 10:57
-
-
Save etherealite/4372649 to your computer and use it in GitHub Desktop.
Single query solution to finding nearest donees with matching timeslots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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