@@ -18,11 +18,15 @@ class Support
18
18
19
19
def initialize ( model_class , options )
20
20
@model_class = model_class
21
+
22
+ # Detect if we're using SQLite and disable advisory locks
23
+ default_with_advisory_lock = !connection . adapter_name . downcase . include? ( 'sqlite' )
24
+
21
25
@options = {
22
26
:parent_column_name => 'parent_id' ,
23
27
:dependent => :nullify , # or :destroy or :delete_all -- see the README
24
28
:name_column => 'name' ,
25
- :with_advisory_lock => true ,
29
+ :with_advisory_lock => default_with_advisory_lock ,
26
30
:numeric_order => false
27
31
} . merge ( options )
28
32
raise ArgumentError , "name_column can't be 'path'" if options [ :name_column ] == 'path'
@@ -34,14 +38,10 @@ def initialize(model_class, options)
34
38
def hierarchy_class_for_model
35
39
parent_class = model_class . module_parent
36
40
hierarchy_class = parent_class . const_set ( short_hierarchy_class_name , Class . new ( model_class . superclass ) )
37
- use_attr_accessible = use_attr_accessible?
38
- include_forbidden_attributes_protection = include_forbidden_attributes_protection?
39
41
model_class_name = model_class . to_s
40
42
hierarchy_class . class_eval do
41
- include ActiveModel ::ForbiddenAttributesProtection if include_forbidden_attributes_protection
42
43
belongs_to :ancestor , class_name : model_class_name
43
44
belongs_to :descendant , class_name : model_class_name
44
- attr_accessible :ancestor , :descendant , :generations if use_attr_accessible
45
45
def ==( other )
46
46
self . class == other . class && ancestor_id == other . ancestor_id && descendant_id == other . descendant_id
47
47
end
0 commit comments