activerecord-import 0.18.2 → 0.18.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ebf1fdae1a4d300498ed6ba18ea8d4039697734
4
- data.tar.gz: 41e6dfff68a59c0fd9184691cbe6731cc420df8d
3
+ metadata.gz: 32bb7874255a2f1979d7fc370e46c9c614c362df
4
+ data.tar.gz: 7b45f6b4f22e64c032d320b34fa0989af63fb4aa
5
5
  SHA512:
6
- metadata.gz: ba3161f35e5521a4febe1a66e729f9a9c549620f54119992d87a834148dc3a42f9e28f3f4c4ca9fb722a0c73639ca678db6d9363325fe6e73a5fb61b58422c59
7
- data.tar.gz: 4248f96c0adbd65300e1ba161ea91fcf707ac151523121ac9bc541d24cec8f32229bde28ac1783ea6ec69c1f3043f3ac5b5a06c094d2fe9f2c04f952128a0cf6
6
+ metadata.gz: fdba083a35bde877674eaadb6bccd5cb83d285370926ef8ca557f0fe3cef08912d011599513ef640f0e1f5bd3dcfd9d0bb0a6979040d08ae1424118035ef93b4
7
+ data.tar.gz: 570dc7bb80545e93cb00114ddf2f09795b410b402e3ba5cd3c3023fc18e974b53d7fc0b78a684440707b7fc7d9163fba84ea8df077d0a7214d2b0eb0556563df
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## Changes in 0.18.3
2
+
3
+ ### Fixes
4
+
5
+ * Set models new_record attribute to false when importing with
6
+ :on_duplicate_key_ignore. Thanks to @nijikon, @jkowens via \#416.
7
+
1
8
  ## Changes in 0.18.2
2
9
 
3
10
  ### Fixes
@@ -521,9 +521,7 @@ class ActiveRecord::Base
521
521
 
522
522
  # if we have ids, then set the id on the models and mark the models as clean.
523
523
  if models && support_setting_primary_key_of_imported_objects?
524
- if options[:recursive] || !(options[:ignore] || options[:on_duplicate_key_ignore])
525
- set_attributes_and_mark_clean(models, return_obj, timestamps)
526
- end
524
+ set_attributes_and_mark_clean(models, return_obj, timestamps)
527
525
 
528
526
  # if there are auto-save associations on the models we imported that are new, import them as well
529
527
  import_associations(models, options.dup) if options[:recursive]
@@ -643,18 +641,24 @@ class ActiveRecord::Base
643
641
  def set_attributes_and_mark_clean(models, import_result, timestamps)
644
642
  return if models.nil?
645
643
  models -= import_result.failed_instances
646
- import_result.ids.each_with_index do |id, index|
647
- model = models[index]
648
- model.id = id
644
+ models.each do |model|
649
645
  if model.respond_to?(:clear_changes_information) # Rails 4.0 and higher
650
646
  model.clear_changes_information
651
647
  else # Rails 3.2
652
648
  model.instance_variable_get(:@changed_attributes).clear
653
649
  end
654
650
  model.instance_variable_set(:@new_record, false)
651
+ end
655
652
 
656
- timestamps.each do |attr, value|
657
- model.send(attr + "=", value)
653
+ # if ids were returned for all models we know all were updated
654
+ if models.size == import_result.ids.size
655
+ import_result.ids.each_with_index do |id, index|
656
+ model = models[index]
657
+ model.id = id
658
+
659
+ timestamps.each do |attr, value|
660
+ model.send(attr + "=", value)
661
+ end
658
662
  end
659
663
  end
660
664
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Import
3
- VERSION = "0.18.2".freeze
3
+ VERSION = "0.18.3".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.2
4
+ version: 0.18.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-05 00:00:00.000000000 Z
11
+ date: 2017-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord