title: Ruby on Rails - order not working with distinct.pluck
body: <p><strong>app/model/line_item.rb</strong></p>
  <pre><code>class LineItem &lt; ApplicationRecord
    default_scope { order(:order_date, :line_item_index) }
    scope :sorted, -&gt; { order(:order_date, :line_item_index) }
    scope :open_order_names, -&gt; { distinct.pluck(:order_name) }
  end
  </code></pre>
  <p>What I have tried:</p>
  <pre><code>LineItem.open_order_names        # Way 1
  LineItem.sorted.open_order_names # Way 2
  LineItem.open_order_names.sorted # Way 3
  </code></pre>
  <p>But I am always getting this error.</p>
  <pre><code>ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
  LINE 1: ...ne_items&quot;.&quot;order_name&quot; FROM &quot;line_items&quot; ORDER BY &quot;line_item...
                                                                   ^
  ):
  </code></pre>
  <p>Anyone can help me?</p>