title: Rails: How to use "joins" in sql query for a has_one association
body: <p>I have a User model and a Profile model. Each User has_one profile. The profile has a city attribute. Now, I want the index action of the Users controller to pull all users with the same city as the current_user. So I have this code in the controller:</p>
  
  <pre><code>def index @users = User.same_city_as(current_user).paginate :page =&gt; params[:page], :per_page =&gt; 10 end
  </code></pre>
  
  <p>I also have this is in the User model:</p>
  
  <pre><code>scope :same_city_as, lambda { |user| joins(:profile).where(:profile =&gt; {:city =&gt; user.profile.city} ) }
  </code></pre>
  
  <p>This does not work. I am getting this error " "PGError: ERROR: missing FROM-clause entry for table "profile" ".</p>