Rails Postgresql Error ORDER clause

Postgresql ORDER clause or be used in a aggregate function

While working in a rails project recently, I step on an error that say: PG::Error: ERROR: column "number" must appear in the GROUP BY clause or be used in an aggregate function, I didn’t have any idea how to solve it.


Rails and select

In a rails project I’m working on I was trying to select from the database some sales with some conditions.

To start the Sale model has multiples associations .

class Sale < ActiveRecord::Base
  belongs_to :voucher
  belongs_to :client
  has_many :line_items, dependent: :destroy
  has_many :bills

So the goal of this select was to obtain all the Sales where the LineItems has express_checkout set it to true.