activeentity 0.0.1.beta13 → 0.0.1.beta14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_entity/gem_version.rb +1 -1
- data/lib/active_entity/nested_attributes.rb +15 -46
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e54d10db138ce5521aa1ab4fde237c75a7aa3e865973ed5a3ec48a55fbff0e7d
|
4
|
+
data.tar.gz: 2604112ec917bddac683e8416787810075a7df1365903d2e36b40b5bc03e9256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81bb5e2f93bba71814227e5076368816c7b2eb615b1f81c890330b1653f637d8a7a4a9d43533d726b3cafc2a603a1e61c2d29f352c1d64695d02f637559f56c5
|
7
|
+
data.tar.gz: 6624cf0afcdd210b7ae461b67ecb23c7d39332faa61a1c4d23d530c074660aefcb6e209772c4c0c715d772fa7b466dc30d6f0fd8c715f4f6a91b15d040cc4de8
|
@@ -402,33 +402,23 @@ module ActiveEntity
|
|
402
402
|
# update_only is true, and a <tt>:_destroy</tt> key set to a truthy value,
|
403
403
|
# then the existing record will be marked for destruction.
|
404
404
|
def assign_nested_attributes_for_one_to_one_association(association_name, attributes)
|
405
|
-
options = nested_attributes_options[association_name]
|
406
405
|
if attributes.respond_to?(:permitted?)
|
407
406
|
attributes = attributes.to_h
|
408
407
|
end
|
409
408
|
attributes = attributes.with_indifferent_access
|
410
409
|
existing_record = send(association_name)
|
411
410
|
|
412
|
-
|
413
|
-
(options[:update_only] || existing_record.id.to_s == attributes["id"].to_s)
|
414
|
-
assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy]) unless call_reject_if(association_name, attributes)
|
415
|
-
|
416
|
-
elsif attributes["id"].present?
|
417
|
-
raise_nested_attributes_record_not_found!(association_name, attributes["id"])
|
418
|
-
|
419
|
-
elsif !reject_new_record?(association_name, attributes)
|
420
|
-
assignable_attributes = attributes.except(*UNASSIGNABLE_KEYS)
|
411
|
+
assignable_attributes = attributes.except(*UNASSIGNABLE_KEYS)
|
421
412
|
|
422
|
-
|
423
|
-
|
424
|
-
|
413
|
+
if existing_record
|
414
|
+
existing_record.assign_attributes(assignable_attributes)
|
415
|
+
association(association_name).initialize_attributes(existing_record)
|
416
|
+
else
|
417
|
+
method = :"build_#{association_name}"
|
418
|
+
if respond_to?(method)
|
419
|
+
send(method, assignable_attributes)
|
425
420
|
else
|
426
|
-
|
427
|
-
if respond_to?(method)
|
428
|
-
send(method, assignable_attributes)
|
429
|
-
else
|
430
|
-
raise ArgumentError, "Cannot build association `#{association_name}'. Are you trying to build a polymorphic one-to-one association?"
|
431
|
-
end
|
421
|
+
raise ArgumentError, "Cannot build association `#{association_name}'. Are you trying to build a polymorphic one-to-one association?"
|
432
422
|
end
|
433
423
|
end
|
434
424
|
end
|
@@ -475,43 +465,22 @@ module ActiveEntity
|
|
475
465
|
if attributes_collection.is_a? Hash
|
476
466
|
keys = attributes_collection.keys
|
477
467
|
attributes_collection = if keys.include?("id") || keys.include?(:id)
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
468
|
+
[attributes_collection]
|
469
|
+
else
|
470
|
+
attributes_collection.values
|
471
|
+
end
|
482
472
|
end
|
483
473
|
|
484
474
|
association = association(association_name)
|
485
475
|
|
486
|
-
|
476
|
+
association.target.clear
|
487
477
|
|
488
478
|
attributes_collection.each do |attributes|
|
489
479
|
if attributes.respond_to?(:permitted?)
|
490
480
|
attributes = attributes.to_h
|
491
481
|
end
|
492
482
|
attributes = attributes.with_indifferent_access
|
493
|
-
|
494
|
-
if attributes["id"].blank?
|
495
|
-
unless reject_new_record?(association_name, attributes)
|
496
|
-
association.reader.build(attributes.except(*UNASSIGNABLE_KEYS))
|
497
|
-
end
|
498
|
-
elsif existing_record = existing_records.detect { |record| record.id.to_s == attributes["id"].to_s }
|
499
|
-
unless call_reject_if(association_name, attributes)
|
500
|
-
# Make sure we are operating on the actual object which is in the association's
|
501
|
-
# proxy_target array (either by finding it, or adding it if not found)
|
502
|
-
# Take into account that the proxy_target may have changed due to callbacks
|
503
|
-
target_record = association.target.detect { |record| record.id.to_s == attributes["id"].to_s }
|
504
|
-
if target_record
|
505
|
-
existing_record = target_record
|
506
|
-
else
|
507
|
-
association.add_to_target(existing_record, :skip_callbacks)
|
508
|
-
end
|
509
|
-
|
510
|
-
assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
|
511
|
-
end
|
512
|
-
else
|
513
|
-
raise_nested_attributes_record_not_found!(association_name, attributes["id"])
|
514
|
-
end
|
483
|
+
association.reader.build(attributes.except(*UNASSIGNABLE_KEYS))
|
515
484
|
end
|
516
485
|
end
|
517
486
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeentity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.beta14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jasl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|