357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
# File 'lib/reactive_record/active_record/class_methods.rb', line 357
def _react_param_conversion(param, opt = nil)
param = Native(param)
param = JSON.from_object(param.to_n) if param.is_a? Native::Object
result =
if param.is_a? self
param
elsif param.is_a? Hash
if opt == :validate_only
klass = ReactiveRecord::Base.infer_type_from_hash(self, param)
klass == self || klass < self
else
target =
if param[primary_key]
find(param[primary_key])
else
new
end
associations = reflect_on_all_associations
param = param.collect do |key, value|
assoc = associations.detect do |association|
association.association_foreign_key == key
end
if assoc
if value
[assoc.attribute, { id: [value] }]
else
[assoc.attribute, [nil]]
end
else
[key, [value]]
end
end
ReactiveRecord::Base.load_data do
ReactiveRecord::ServerDataCache.load_from_json(Hash[param], target)
end
target.cast_to_current_sti_type
end
end
result
end
|