I am running a basic rails 4 app that uses Google maps to locate users on a map.
I am trying to write a query that finds a set of users by multiple attributes. Relationships are:
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? I am using the Geocoded gem, which provides the .near method. So I query a set of locations by params[:distance], then based on that set of objects, I need to query the number of children.count <= params[:number_of_children].
PG::FeatureNotSupported: ERROR: cross-database references are not implemented: locations.users.children.count
The initialization of the @close instance var, gets an list of locations near a given location. I am then trying to filter those objects by a given associated locations.users.children.count.