title: Postgresql cross-database references in Rails
body: <p>I'm building a search for and got stuck on a cross-database references error</p>
  
  <pre><code>activities = Activity.order(:name).includes([:profile =&gt; :country])
  activities = activities.where("lower(activities.city) like ?", "%#{params[:activity_search][:city].downcase}%") unless params[:activity_search][:city] == ""      
  activities = activities.where("activities.sport_id =?", params[:activity_search][:sport_id])
  </code></pre>
  
  <p>I'm trying to add something like this:</p>
  
  <pre><code>activities = activities.where("activities.profiles.country.id =?", params[:activity_search][:country_id])
  </code></pre>
  
  <p>an activity's country is the same as the activity creator's country.</p>
  
  <p>How can I add this constraint in my query?</p>
  
  <p>Thanks for your help </p>