1
- class Tag < ActiveRecord ::Base
2
- has_closure_tree :dependent => :destroy , :order => :name
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationRecord < ActiveRecord ::Base
4
+ self . abstract_class = true
5
+
6
+ # connects_to database: { writing: :primary, reading: :primary }
7
+ end
8
+
9
+ class SecondDatabaseRecord < ActiveRecord ::Base
10
+ self . abstract_class = true
11
+
12
+ # connects_to database: { writing: :secondary, reading: :secondary }
13
+ end
14
+ class Tag < ApplicationRecord
15
+ has_closure_tree dependent : :destroy , order : :name
3
16
before_destroy :add_destroyed_tag
4
17
5
18
def to_s
@@ -8,11 +21,11 @@ def to_s
8
21
9
22
def add_destroyed_tag
10
23
# Proof for the tests that the destroy rather than the delete method was called:
11
- DestroyedTag . create ( : name => name )
24
+ DestroyedTag . create ( name : to_s )
12
25
end
13
26
end
14
27
15
- class UUIDTag < ActiveRecord :: Base
28
+ class UUIDTag < ApplicationRecord
16
29
self . primary_key = :uuid
17
30
before_create :set_uuid
18
31
has_closure_tree dependent : :destroy , order : 'name' , parent_column_name : 'parent_uuid'
@@ -28,62 +41,62 @@ def to_s
28
41
29
42
def add_destroyed_tag
30
43
# Proof for the tests that the destroy rather than the delete method was called:
31
- DestroyedTag . create ( : name => name )
44
+ DestroyedTag . create ( name : to_s )
32
45
end
33
46
end
34
47
35
- class DestroyedTag < ActiveRecord :: Base
48
+ class DestroyedTag < ApplicationRecord
36
49
end
37
50
38
- class Group < ActiveRecord :: Base
51
+ class Group < ApplicationRecord
39
52
has_closure_tree_root :root_user
40
53
end
41
54
42
- class Grouping < ActiveRecord :: Base
43
- has_closure_tree_root :root_person , class_name : " User" , foreign_key : :group_id
55
+ class Grouping < ApplicationRecord
56
+ has_closure_tree_root :root_person , class_name : ' User' , foreign_key : :group_id
44
57
end
45
58
46
- class UserSet < ActiveRecord :: Base
47
- has_closure_tree_root :root_user , class_name : " Useur"
59
+ class UserSet < ApplicationRecord
60
+ has_closure_tree_root :root_user , class_name : ' Useur'
48
61
end
49
62
50
- class Team < ActiveRecord :: Base
51
- has_closure_tree_root :root_user , class_name : " User" , foreign_key : :grp_id
63
+ class Team < ApplicationRecord
64
+ has_closure_tree_root :root_user , class_name : ' User' , foreign_key : :grp_id
52
65
end
53
66
54
- class User < ActiveRecord :: Base
55
- acts_as_tree : parent_column_name => " referrer_id" ,
56
- :name_column => 'email' ,
57
- :hierarchy_class_name => 'ReferralHierarchy' ,
58
- :hierarchy_table_name => 'referral_hierarchies'
67
+ class User < ApplicationRecord
68
+ acts_as_tree parent_column_name : ' referrer_id' ,
69
+ name_column : 'email' ,
70
+ hierarchy_class_name : 'ReferralHierarchy' ,
71
+ hierarchy_table_name : 'referral_hierarchies'
59
72
60
73
has_many :contracts , inverse_of : :user
61
74
belongs_to :group # Can't use and don't need inverse_of here when using has_closure_tree_root.
62
75
63
76
def indirect_contracts
64
- Contract . where ( : user_id => descendant_ids )
77
+ Contract . where ( user_id : descendant_ids )
65
78
end
66
79
67
80
def to_s
68
81
email
69
82
end
70
83
end
71
84
72
- class Contract < ActiveRecord :: Base
85
+ class Contract < ApplicationRecord
73
86
belongs_to :user , inverse_of : :contracts
74
87
belongs_to :contract_type , inverse_of : :contracts
75
88
end
76
89
77
- class ContractType < ActiveRecord :: Base
90
+ class ContractType < ApplicationRecord
78
91
has_many :contracts , inverse_of : :contract_type
79
92
end
80
93
81
- class Label < ActiveRecord :: Base
94
+ class Label < ApplicationRecord
82
95
# make sure order doesn't matter
83
- acts_as_tree : order => :column_whereby_ordering_is_inferred , # <- symbol, and not "sort_order"
84
- :numeric_order => true ,
85
- :parent_column_name => " mother_id" ,
86
- :dependent => :destroy
96
+ acts_as_tree order : :column_whereby_ordering_is_inferred , # <- symbol, and not "sort_order"
97
+ numeric_order : true ,
98
+ parent_column_name : ' mother_id' ,
99
+ dependent : :destroy
87
100
88
101
def to_s
89
102
"#{ self . class } : #{ name } "
@@ -99,13 +112,13 @@ class DateLabel < Label
99
112
class DirectoryLabel < Label
100
113
end
101
114
102
- class LabelWithoutRootOrdering < ActiveRecord :: Base
115
+ class LabelWithoutRootOrdering < ApplicationRecord
103
116
# make sure order doesn't matter
104
- acts_as_tree : order => :column_whereby_ordering_is_inferred , # <- symbol, and not "sort_order"
105
- :numeric_order => true ,
106
- :dont_order_roots => true ,
107
- :parent_column_name => " mother_id" ,
108
- :hierarchy_table_name => " label_hierarchies"
117
+ acts_as_tree order : :column_whereby_ordering_is_inferred , # <- symbol, and not "sort_order"
118
+ numeric_order : true ,
119
+ dont_order_roots : true ,
120
+ parent_column_name : ' mother_id' ,
121
+ hierarchy_table_name : ' label_hierarchies'
109
122
110
123
self . table_name = "#{ table_name_prefix } labels#{ table_name_suffix } "
111
124
@@ -114,20 +127,21 @@ def to_s
114
127
end
115
128
end
116
129
117
- class CuisineType < ActiveRecord :: Base
130
+ class CuisineType < ApplicationRecord
118
131
acts_as_tree
119
132
end
120
133
121
134
module Namespace
122
135
def self . table_name_prefix
123
136
'namespace_'
124
137
end
125
- class Type < ActiveRecord ::Base
138
+
139
+ class Type < ApplicationRecord
126
140
has_closure_tree dependent : :destroy
127
141
end
128
142
end
129
143
130
- class Metal < ActiveRecord :: Base
144
+ class Metal < ApplicationRecord
131
145
self . table_name = "#{ table_name_prefix } metal#{ table_name_suffix } "
132
146
has_closure_tree order : 'sort_order' , name_column : 'value'
133
147
self . inheritance_column = 'metal_type'
@@ -139,6 +153,6 @@ class Adamantium < Metal
139
153
class Unobtanium < Metal
140
154
end
141
155
142
- class MenuItem < ActiveRecord :: Base
156
+ class MenuItem < SecondDatabaseRecord
143
157
has_closure_tree touch : true , with_advisory_lock : false
144
158
end
0 commit comments