I have models named User and Service
User model has the following columns: user_name
and location_name
Service model has the following columns: user_location
and service_name
Now i want to search for the Users who are residing in a particular location and providing a particular service.
The main problem is a user can provide more than one service.
I have achieved the functionality in the following way:
serv1 = Services.find_by_service_name(service_name)
res = []
serv1.each do |s|
res.push s if s.user_location == location_name
end
Can anybody suggest a better way?