title: ActiveRecord unknown column
body: <p>I ran into a little problem I have a has_many through relationship here is the code for the models</p>
  
  <pre class="lang-ruby prettyprint-override"><code>class User &lt; ActiveRecord::Base
    has_many :friendships
    has_many :followings, :through =&gt; :friendships, :foreign_key =&gt; "followed_id"
  end
  
  class Friendship &lt; ActiveRecord::Base
    belongs_to :user 
    belongs_to :following, :class_name =&gt; "User", :foreign_key =&gt; "followed_id"
  end
  </code></pre>
  
  <p>now at the console I can type u = User.first and then u.friendships.first.following this gives me the first user u is following, but when I type u.friendships.last.following I get this error</p>
  
  <p>the SELECT statement from u.friendships.first.following</p>
  
  <pre><code>Friendship Load (0.3ms)  SELECT `friendships`.* FROM `friendships` WHERE `friendships`.`user_id` = 208 LIMIT 1
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 209 LIMIT 1
  </code></pre>
  
  <p>and the SELECT statement from u.friendships.last.following</p>
  
  <pre><code>Friendship Load (0.3ms)  SELECT `friendships`.* FROM `friendships` WHERE `friendships`.`user_id` = 208 ORDER BY `friendships`.`` DESC LIMIT 1
  </code></pre>
  
  <pre class="lang-ruby prettyprint-override"><code>ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'friendships.' in 'order
  clause': SELECT  `friendships`.* FROM `friendships`  WHERE `friendships`.`user_id` = 208
  ORDER BY `friendships`.`` DESC LIMIT 1
  </code></pre>
  
  <p>if I then run u.friendships and then u.friendships.last.following again, I don't get the error anymore, why is that?</p>