Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Filter using a model array? #391

Open
simkessy opened this issue Jul 27, 2015 · 1 comment
Open

Filter using a model array? #391

simkessy opened this issue Jul 27, 2015 · 1 comment

Comments

@simkessy
Copy link

I'm trying to filter results based on an array of models

I have 4 models: Venues, Facility, Availability and Activities.

This is the squeel I put together to return Availabilities:

@search = Availability.joins{facility.venue.activities}.where{(activities.id == activity) & (booking_id == nil) & (start_time <= datetime )}    

I'm trying to figure out how to filter the results based on an array of Venues which are in proximity to the location entered.

I can get a list of Venues using geocoder gem: venues = Venue.near("Some location") , how would I add it above to get Availabilities only from the returned venues?

@simkessy
Copy link
Author

I solved it doing this:

@search = Availability.joins{facility.venue.activities}
                      .where{
                        (activities.id == s_activity) &
                        (booking_id == nil) &
                        (start_time >= s_start_time ) &
                        (end_time <= s_end_time ) &
                        (facility.venue_id.in near_by_venues)
                      }
                      .order{start_time.desc}

If anyone has any suggestions on how I could improve this, that would be great. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant