PostgreSQL, Rails and :order => problem

后端 未结 3 1323
灰色年华
灰色年华 2021-01-02 16:32

I have the following line in my ActiveRecord model:

class Record < ActiveRecord::Base
    has_many :users, :through => :record_users, :uniq => true,         


        
3条回答
  •  孤城傲影
    2021-01-02 16:55

    I suppose you could call it a bug in ActiveRecord. PosgreSQL is a bit more restrictive than MySQL. You can help out ActiveRecord by setting up the association like this instead:

    class Record < ActiveRecord::Base
      has_many :users,
       :through => :record_users,
       :select => 'DISTINCT users.*, record_users.index',
       :order => "record_users.index ASC"
    

提交回复
热议问题