File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,13 @@ module Model
55 extend ActiveSupport ::Concern
66
77 included do
8- belongs_to :parent ,
9- class_name : _ct . model_class . to_s ,
10- foreign_key : _ct . parent_column_name ,
11- inverse_of : :children ,
12- touch : _ct . options [ :touch ]
8+
9+ belongs_to :parent , nil , *_ct . belongs_to_with_optional_option (
10+ class_name : _ct . model_class . to_s ,
11+ foreign_key : _ct . parent_column_name ,
12+ inverse_of : :children ,
13+ touch : _ct . options [ :touch ] ,
14+ optional : true )
1315
1416 order_by_generations = "#{ _ct . quoted_hierarchy_table_name } .generations asc"
1517
Original file line number Diff line number Diff line change @@ -76,6 +76,10 @@ def scope_with_order(scope, additional_order_by = nil)
7676 end
7777 end
7878
79+ def belongs_to_with_optional_option ( opts )
80+ [ ActiveRecord ::VERSION ::MAJOR < 5 ? opts . except ( :optional ) : opts ]
81+ end
82+
7983 # lambda-ize the order, but don't apply the default order_option
8084 def has_many_without_order_option ( opts )
8185 [ lambda { order ( opts [ :order ] ) } , opts . except ( :order ) ]
You can’t perform that action at this time.
0 commit comments