2017-11-13 8 views
0

システムルビー/ RoRの、ActiveRecordの - のRorのメソッドを "アレンジ" とモデルの "スーパー" を使用

[2017-11-13 18:34:46] INFO WEBrick 1.3.1 
[2017-11-13 18:34:46] INFO ruby 1.9.3 (2012-02-16) [x86_64-linux] 

モデルは、(currenctバージョンを)働いていること

class Expenditure < ActiveRecord::Base 
... 
    class << self 
    def arrange 
     super(:order => :name) 
    end 
... 

は、私は1つを追加しようとしました変更の順序のためのより多くのフィールド。 "sort_order"。 私は をredifynedたのActiveRecord、方法arrangeを見つけることができない私は、ancestry宝石から

super.order(:sort_order, :name) 
+0

を使用することができますか? –

+0

"名前"の順序付けの前に "sort_order"を追加すると、次のようなクエリの終わりが表示されます: '... ORDER BY(expenditures.ancestryがnullの場合は0、それ以外は0の場合1)、expenditures.ancestry、name'、それで私はスーパー滞在をしなければならないのです –

+0

私はIdiaを持っていません、どこの 'arrange'メソッドから –

答えて

0

arrange方法... unsuccesfully

super(:order => :sort_order, :name) 

試してみました。それは私が正しくあなたの質問を理解している場合https://github.com/stefankroes/ancestry/blob/8482196e32ac46a9d89c5e3b2d7080e4b830b1d0/lib/ancestry/class_methods.rb#L31

# Arrangement 
    def arrange options = {} 
     # Get all nodes ordered by ancestry and start sorting them into an empty hash 
     arrange_nodes self.ancestry_base_class.reorder(options.delete(:order)).where(options) 
    end 
+0

はい、私は' ancestry(2.0.0) 'ありがとうございました –

+0

私は理解できません、どうすれば2つのパラメータソートのために。パラメータはHahsのようですが、 '(:order =>:sort_order、:order =>:name)'または '({:order =>:sort_order、:order =>:name} ')のようには動作しませんでした。 –

+0

':order =>" sort_order ASC、name ASC "' などがあります。詳細はこちらhttps://stackoverflow.com/questions/3587776/ruby-on-rails-how-do-i-sort -with-two-columns-using-activerecord –

0

わからないのですが、私はあなたがorder方法(ARで定義されたarrange方法はありませんsuper「原因)self使用していたと思います。あなたは昇順でsort_ordernameでそれを注文したい場合は、あなたの方法は次のようになります。

def arrange 
    self.order(:sort_order => :asc, :name => :asc) 
end 

あなたもselfを省略し、ちょうどあなたが発注するために使用したいん属性self.order(:sort_order => :asc, :name => :asc)

+0

いいえ、私は 'スーパー'が必要です –