Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 4基于父资源的子集查询嵌套资源_Ruby On Rails_Google Maps_Activerecord_Geocoding - Fatal编程技术网

Ruby on rails Rails 4基于父资源的子集查询嵌套资源

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

我正在运行一个基本的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.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