File tree 3 files changed +9
-3
lines changed 3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ module Model
13
13
touch : _ct . options [ :touch ] ,
14
14
optional : true )
15
15
16
- order_by_generations = Arel . sql ( "#{ _ct . quoted_hierarchy_table_name } .generations ASC" )
16
+ order_by_generations = -> { Arel . sql ( "#{ _ct . quoted_hierarchy_table_name } .generations ASC" ) }
17
17
18
18
has_many :children , *_ct . has_many_with_order_option (
19
19
class_name : _ct . model_class . to_s ,
Original file line number Diff line number Diff line change @@ -82,12 +82,15 @@ def belongs_to_with_optional_option(opts)
82
82
83
83
# lambda-ize the order, but don't apply the default order_option
84
84
def has_many_without_order_option ( opts )
85
- [ lambda { order ( opts [ :order ] ) } , opts . except ( :order ) ]
85
+ [ lambda { order ( opts [ :order ] . call ) } , opts . except ( :order ) ]
86
86
end
87
87
88
88
def has_many_with_order_option ( opts )
89
89
order_options = [ opts [ :order ] , order_by ] . compact
90
- [ lambda { order ( order_options ) } , opts . except ( :order ) ]
90
+ [ lambda {
91
+ order_options = order_options . map { |o | o . is_a? ( Proc ) ? o . call : o }
92
+ order ( order_options )
93
+ } , opts . except ( :order ) ]
91
94
end
92
95
93
96
def ids_from ( scope )
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ def order_option?
17
17
end
18
18
19
19
def order_is_numeric?
20
+ # skip if database is not connected.
21
+ return false unless ::ActiveRecord ::Base . connected?
22
+
20
23
# The table might not exist yet (in the case of ActiveRecord::Observer use, see issue 32)
21
24
return false if !order_option? || !model_class . table_exists?
22
25
c = model_class . columns_hash [ order_column ]
You can’t perform that action at this time.
0 commit comments