active_record_upsert 0.9.3 → 0.9.4

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
  SHA256:
3
- metadata.gz: 48b9c738ca1c46087a4bcc14ad389d945e0ce700b20a8585543c193c5a2555ed
4
- data.tar.gz: 39b75431ad9dc73ade303206211c655ea354cdfbab8998ffb783bf5e00dab46c
3
+ metadata.gz: de123fd4fdfdb6a7cbebd1aa2d7232ecfdebf014723e4b64c7e0ad3a8c8f61b4
4
+ data.tar.gz: 27d972189bb6e75c48eb43cc7cb93362991ad237ffe84a25349fe148b648187b
5
5
  SHA512:
6
- metadata.gz: d44e12c8506b54748db2a723c237f5eb7d558c59f62d9aaf3dea5e38ff3c8aa0709ed8475754c146372acfc3c1ccfa797f167483d314acb1cd2179e9d1e601fd
7
- data.tar.gz: e7a045afae796b1c20bb1043f815636aee056960dc3de077374cc8029dcdcedf2c4441cdabf8b22efc1f927a451b163192820f7f741c54ab28dbb59cc9cc7036
6
+ metadata.gz: c33829cb05d8c261c850e3dcde28842cd50824369231c58b936c30bf6ddae64fb76c68ec594e4e62f4578eb4940d51d23033056a31bfeea2da4e4ad821e14070
7
+ data.tar.gz: f8943ad447f87aa33b8ae4facdfda3ae7368c8d3e9b3c7bfc1985ddfd97dd2654670620ed803ed52f38034c6c4bc7a49fdc0d8135be83f16504b2efcdb59ed50
@@ -1,5 +1,5 @@
1
1
  group :development, :test do
2
- gem 'rails', '>= 5.2.0.rc1', '< 6.0'
2
+ gem 'rails', '>= 5.2.1', '< 6.0'
3
3
  end
4
4
 
5
5
  eval_gemfile "#{__dir__}/Gemfile.base"
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/active_record_upsert.svg)](https://badge.fury.io/rb/active_record_upsert)
2
2
  [![Build Status](https://travis-ci.org/jesjos/active_record_upsert.svg?branch=master)](https://travis-ci.org/jesjos/active_record_upsert)
3
3
  [![Code Climate](https://codeclimate.com/github/jesjos/active_record_upsert/badges/gpa.svg)](https://codeclimate.com/github/jesjos/active_record_upsert)
4
- [![Dependency Status](https://gemnasium.com/badges/github.com/jesjos/active_record_upsert.svg)](https://gemnasium.com/github.com/jesjos/active_record_upsert)
4
+
5
+ # NB: INCOMPATIBILITY
6
+ B/c of a broken build matrix, versions 0.9.2 - 0.9.3 are incompatible with rails < 5.2.1!
5
7
 
6
8
  # ActiveRecordUpsert
7
9
 
@@ -2,11 +2,21 @@ module ActiveRecordUpsert
2
2
  module ActiveRecord
3
3
  module PersistenceExtensions
4
4
  def _upsert_record(upsert_attribute_names = changed, arel_condition = nil)
5
- existing_attributes = arel_attributes_with_values_for_create(self.attributes.keys)
5
+ upsert_attribute_names = upsert_attribute_names.map { |name| _prepare_column(name) } & self.class.column_names
6
+ existing_attributes = arel_attributes_with_values_for_create(self.class.column_names)
6
7
  values = self.class.unscoped.upsert(existing_attributes, upsert_attribute_names, [arel_condition].compact)
7
8
  @new_record = false
9
+ @attributes = self.class.attributes_builder.build_from_database(values.first.to_h)
8
10
  values
9
11
  end
12
+
13
+ def _prepare_column(name)
14
+ if self.class.reflections.key?(name)
15
+ self.class.reflections[name].foreign_key
16
+ else
17
+ name
18
+ end
19
+ end
10
20
  end
11
21
 
12
22
  module RelationExtensions
@@ -20,8 +30,10 @@ module ActiveRecordUpsert
20
30
  on_conflict_binds = binds.select(&upsert_keys_filter)
21
31
  vals_for_upsert = substitutes.select { |s| upsert_keys_filter.call(s.first) }
22
32
 
33
+ target = arel_table[upsert_options.key?(:literal) ? ::Arel::Nodes::SqlLiteral.new(upsert_options[:literal]) : upsert_keys.join(',')]
34
+
23
35
  on_conflict_do_update = ::Arel::OnConflictDoUpdateManager.new
24
- on_conflict_do_update.target = arel_table[upsert_keys.join(',')]
36
+ on_conflict_do_update.target = target
25
37
  on_conflict_do_update.target_condition = self.klass.upsert_options[:where]
26
38
  on_conflict_do_update.wheres = wheres
27
39
  on_conflict_do_update.set(vals_for_upsert)
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordUpsert
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_upsert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesper Josefsson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-09-05 00:00:00.000000000 Z
12
+ date: 2018-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord