我有一個名爲用戶和服務搜索使用兩個密鑰記錄在兩個表中軌
用戶模型的模型有以下欄目:user_name
和location_name
服務模式有以下欄目:user_location
和service_name
現在我想搜索居住在特定位置並提供特定服務的用戶。
主要問題是用戶可以提供多個服務。
我已經實現了通過以下方式功能:
serv1 = Services.find_by_service_name(service_name)
res = []
serv1.each do |s|
res.push s if s.user_location == location_name
end
任何人可以提出一個更好的辦法嗎?