File tree Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ module Model
1313 touch : _ct . options [ :touch ] ,
1414 optional : true )
1515
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" ) }
1717
1818 has_many :children , *_ct . has_many_with_order_option (
1919 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)
8282
8383 # lambda-ize the order, but don't apply the default order_option
8484 def has_many_without_order_option ( opts )
85- [ lambda { order ( opts [ :order ] ) } , opts . except ( :order ) ]
85+ [ lambda { order ( opts [ :order ] . call ) } , opts . except ( :order ) ]
8686 end
8787
8888 def has_many_with_order_option ( opts )
8989 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 ) ]
9194 end
9295
9396 def ids_from ( scope )
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ def order_option?
1717 end
1818
1919 def order_is_numeric?
20+ # skip if database is not connected.
21+ return false unless ::ActiveRecord ::Base . connected?
22+
2023 # The table might not exist yet (in the case of ActiveRecord::Observer use, see issue 32)
2124 return false if !order_option? || !model_class . table_exists?
2225 c = model_class . columns_hash [ order_column ]
You can’t perform that action at this time.
0 commit comments