我有这个模型:
class User < ActiveRecord::Base
has_many :customers, -> { order('customers.name ASC') }
has_many :stores, -> { order('company_stores.id ASC').uniq }, through: :customers
end
当我尝试
user.stores
我有这个错误:
PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
因为 Rails 执行 a SELECT DISTINCT of company_stores.*
,但在 中ORDER BY
也出现customers.name
我应该放弃协会的秩序吗?