Ruby on rails Rails 4基于父资源的子集查询嵌套资源
我正在运行一个基本的rails 4应用程序,它使用Google地图在地图上定位用户 我正在尝试编写一个查询,通过多个属性查找一组用户。关系包括:Ruby on rails Rails 4基于父资源的子集查询嵌套资源,ruby-on-rails,google-maps,activerecord,geocoding,Ruby On Rails,Google Maps,Activerecord,Geocoding,我正在运行一个基本的rails 4应用程序,它使用Google地图在地图上定位用户 我正在尝试编写一个查询,通过多个属性查找一组用户。关系包括: User has_one :location User has_many :children Location belongs_to :user Children belongs_to :user @close = Location.near([current_user.location.latitude, current_user.locatio
User has_one :location
User has_many :children
Location belongs_to :user
Children belongs_to :user
@close = Location.near([current_user.location.latitude, current_user.location.longitude], params[:distance])
@close = @close.joins(user: :children).where('locations.users.children.count <= ?', params[:number_of_children]) if params[:number_of_children].present?
编辑
@close
实例变量的初始化将获取给定位置附近的位置列表。然后,我尝试通过给定的关联位置来过滤这些对象。users.children.count
应该是:@close.join中的用户修改为您所注意到的内容,我想知道是否需要将其修改为joins。(users::children)?我试过了,但没用,但是……你有个“打字错误”。你想要得到的是用户。如果你在上实现了计数器缓存,那么你的用户有很多:children
关联。我没有关联的计数器方法,但我想我可以写一个,我会试一试计数器缓存工作得很好。如果你(MichaelSzyndel)想要创建一个答案,我可以标记它已解决。
PG::FeatureNotSupported: ERROR: cross-database references are not implemented: locations.users.children.count