Skip to content

Commit cb9ed9b

Browse files
committed
Merge pull request #342 from cerebris/fix_transactional
Fix transactional
2 parents 871362c + be508cf commit cb9ed9b

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

lib/jsonapi/operation.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class FindOperation < Operation
1717
attr_reader :filters, :include_directives, :sort_criteria, :paginator
1818

1919
def initialize(resource_klass, options = {})
20+
super(resource_klass, options)
2021
@filters = options[:filters]
2122
@include_directives = options[:include_directives]
2223
@sort_criteria = options.fetch(:sort_criteria, [])
2324
@paginator = options[:paginator]
2425
@transactional = false
25-
super(resource_klass, options)
2626
end
2727

2828
def record_count
@@ -70,10 +70,10 @@ class ShowOperation < Operation
7070
attr_reader :id, :include_directives
7171

7272
def initialize(resource_klass, options = {})
73+
super(resource_klass, options)
7374
@id = options.fetch(:id)
7475
@include_directives = options[:include_directives]
7576
@transactional = false
76-
super(resource_klass, options)
7777
end
7878

7979
def apply
@@ -94,10 +94,10 @@ class ShowRelationshipOperation < Operation
9494
attr_reader :parent_key, :relationship_type
9595

9696
def initialize(resource_klass, options = {})
97+
super(resource_klass, options)
9798
@parent_key = options.fetch(:parent_key)
9899
@relationship_type = options.fetch(:relationship_type)
99100
@transactional = false
100-
super(resource_klass, options)
101101
end
102102

103103
def apply
@@ -116,11 +116,11 @@ class ShowRelatedResourceOperation < Operation
116116
attr_reader :source_klass, :source_id, :relationship_type
117117

118118
def initialize(resource_klass, options = {})
119+
super(resource_klass, options)
119120
@source_klass = options.fetch(:source_klass)
120121
@source_id = options.fetch(:source_id)
121122
@relationship_type = options.fetch(:relationship_type)
122123
@transactional = false
123-
super(resource_klass, options)
124124
end
125125

126126
def apply
@@ -139,14 +139,14 @@ class ShowRelatedResourcesOperation < Operation
139139
attr_reader :source_klass, :source_id, :relationship_type, :filters, :sort_criteria, :paginator
140140

141141
def initialize(resource_klass, options = {})
142+
super(resource_klass, options)
142143
@source_klass = options.fetch(:source_klass)
143144
@source_id = options.fetch(:source_id)
144145
@relationship_type = options.fetch(:relationship_type)
145146
@filters = options[:filters]
146147
@sort_criteria = options[:sort_criteria]
147148
@paginator = options[:paginator]
148149
@transactional = false
149-
super(resource_klass, options)
150150
end
151151

152152
def apply
@@ -168,8 +168,8 @@ class CreateResourceOperation < Operation
168168
attr_reader :data
169169

170170
def initialize(resource_klass, options = {})
171-
@data = options.fetch(:data)
172171
super(resource_klass, options)
172+
@data = options.fetch(:data)
173173
end
174174

175175
def apply
@@ -186,8 +186,8 @@ def apply
186186
class RemoveResourceOperation < Operation
187187
attr_reader :resource_id
188188
def initialize(resource_klass, options = {})
189-
@resource_id = options.fetch(:resource_id)
190189
super(resource_klass, options)
190+
@resource_id = options.fetch(:resource_id)
191191
end
192192

193193
def apply
@@ -205,9 +205,9 @@ class ReplaceFieldsOperation < Operation
205205
attr_reader :data, :resource_id
206206

207207
def initialize(resource_klass, options = {})
208+
super(resource_klass, options)
208209
@resource_id = options.fetch(:resource_id)
209210
@data = options.fetch(:data)
210-
super(resource_klass, options)
211211
end
212212

213213
def apply
@@ -222,10 +222,10 @@ class ReplaceToOneRelationshipOperation < Operation
222222
attr_reader :resource_id, :relationship_type, :key_value
223223

224224
def initialize(resource_klass, options = {})
225+
super(resource_klass, options)
225226
@resource_id = options.fetch(:resource_id)
226227
@key_value = options.fetch(:key_value)
227228
@relationship_type = options.fetch(:relationship_type).to_sym
228-
super(resource_klass, options)
229229
end
230230

231231
def apply
@@ -240,11 +240,11 @@ class ReplacePolymorphicToOneRelationshipOperation < Operation
240240
attr_reader :resource_id, :relationship_type, :key_value, :key_type
241241

242242
def initialize(resource_klass, options = {})
243+
super(resource_klass, options)
243244
@resource_id = options.fetch(:resource_id)
244245
@key_value = options.fetch(:key_value)
245246
@key_type = options.fetch(:key_type)
246247
@relationship_type = options.fetch(:relationship_type).to_sym
247-
super(resource_klass, options)
248248
end
249249

250250
def apply
@@ -259,10 +259,10 @@ class CreateToManyRelationshipOperation < Operation
259259
attr_reader :resource_id, :relationship_type, :data
260260

261261
def initialize(resource_klass, options)
262+
super(resource_klass, options)
262263
@resource_id = options.fetch(:resource_id)
263264
@data = options.fetch(:data)
264265
@relationship_type = options.fetch(:relationship_type).to_sym
265-
super(resource_klass, options)
266266
end
267267

268268
def apply
@@ -277,10 +277,10 @@ class ReplaceToManyRelationshipOperation < Operation
277277
attr_reader :resource_id, :relationship_type, :data
278278

279279
def initialize(resource_klass, options)
280+
super(resource_klass, options)
280281
@resource_id = options.fetch(:resource_id)
281282
@data = options.fetch(:data)
282283
@relationship_type = options.fetch(:relationship_type).to_sym
283-
super(resource_klass, options)
284284
end
285285

286286
def apply
@@ -295,10 +295,10 @@ class RemoveToManyRelationshipOperation < Operation
295295
attr_reader :resource_id, :relationship_type, :associated_key
296296

297297
def initialize(resource_klass, options)
298+
super(resource_klass, options)
298299
@resource_id = options.fetch(:resource_id)
299300
@associated_key = options.fetch(:associated_key)
300301
@relationship_type = options.fetch(:relationship_type).to_sym
301-
super(resource_klass, options)
302302
end
303303

304304
def apply
@@ -313,9 +313,9 @@ class RemoveToOneRelationshipOperation < Operation
313313
attr_reader :resource_id, :relationship_type
314314

315315
def initialize(resource_klass, options)
316+
super(resource_klass, options)
316317
@resource_id = options.fetch(:resource_id)
317318
@relationship_type = options.fetch(:relationship_type).to_sym
318-
super(resource_klass, options)
319319
end
320320

321321
def apply

lib/jsonapi/operations_processor.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ def process(request)
3333
# Use transactions if more than one operation and if one of the operations can be transactional
3434
# Even if transactional transactions won't be used unless the derived OperationsProcessor supports them.
3535
@transactional = false
36-
if @operations.length > 1
37-
@operations.each do |operation|
38-
@transactional |= operation.transactional
39-
end
36+
@operations.each do |operation|
37+
@transactional |= operation.transactional
4038
end
4139

4240
run_callbacks :operations do

0 commit comments

Comments
 (0)