title: PG error for SELECT DISTINCT, ORDER BY expressions must appear in select list when trying to view on Heroku
body: <p>I am getting this follow error after I added more relationships to my project. On localhost, the page displays perfectly fine. However, I get an error when trying to view it on heroku.</p>
  
  <pre><code>ActiveRecord::StatementInvalid (PG::Error: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
  </code></pre>
  
  <p>Here is my traveldeal controller:</p>
  
  <pre><code>  def show
      @traveldeal = @commentable = Traveldeal.find(params[:id])
      @comments = Comment.all
      @title = @traveldeal.title
      @eventdeals = Eventdeal.tagged_with(@traveldeal.location_tag_list, :any =&gt; true, :order =&gt; 'RANDOM()', :limit =&gt; 3)
    end
  </code></pre>
  
  <p>traveldeal/show.html</p>
  
  <pre><code>&lt;% unless @eventdeals.blank? %&gt;
  
    &lt;h1&gt;Events in the area:&lt;/h1&gt;
  
    &lt;% @eventdeals.each do |eventdeal| %&gt;
      &lt;%= link_to eventdeal do %&gt;
        &lt;!-- content --&gt;
      &lt;% end %&gt;
    &lt;% end %&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>Heroku logs</p>
  
  <p><code>SELECT DISTINCT eventdeals.* FROM "eventdeals" JOIN taggings event_taggings_e9f0e2e  ON event_taggings_e9f0e2e.taggable_id = eventdeals.id AND event_taggings_e9f0e2e.taggable_type = 'Eventdeal' WHERE (event_taggings_e9f0e2e.tag_id = 1 OR event_taggings_e9f0e2e.tag_id = 3 OR event_taggings_e9f0e2e.tag_id = 4 OR event_taggings_e9f0e2e.tag_id = 5) ORDER BY RANDOM()):</code></p>
  
  <p>This code was working so that I only displayed 3 random eventdeals that matched location (through act-as-taggable-on) with a traveldeal.</p>
  
  <p>However, after I added a relationship (related to eventdeals but not traveldeals), I started getting the pg error. </p>
  
  <p>Here are the relationships that was added:</p>
  
  <p>trip.rb</p>
  
  <pre><code>class Trip &lt; ActiveRecord::Base
    has_many :eventdealtrips, :dependent =&gt; :destroy
    has_many :eventdeals, :through =&gt; :eventdealtrips
  end
  </code></pre>
  
  <p>eventdeal.rb</p>
  
  <pre><code>class Eventdeal &lt; ActiveRecord::Base
    has_many :eventdealtrips
    has_many :trips, :through =&gt; :eventdealtrips, :dependent =&gt; :destroy
  end
  </code></pre>
  
  <p>eventdealtrip.rb</p>
  
  <pre><code>class Eventdealtrip &lt; ActiveRecord::Base
    belongs_to :eventdeal
    belongs_to :trip
  end
  </code></pre>
  
  <p>Any advice on how I can still get a random array of 3 eventdeals?</p>
  
  <p>Thanks.</p>