active_record_upsert 0.9.3 → 0.9.4
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/Gemfile.rails-5-2 +1 -1
- data/README.md +3 -1
- data/lib/active_record_upsert/compatibility/rails51.rb +14 -2
- data/lib/active_record_upsert/version.rb +1 -1
- 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: de123fd4fdfdb6a7cbebd1aa2d7232ecfdebf014723e4b64c7e0ad3a8c8f61b4
|
4
|
+
data.tar.gz: 27d972189bb6e75c48eb43cc7cb93362991ad237ffe84a25349fe148b648187b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c33829cb05d8c261c850e3dcde28842cd50824369231c58b936c30bf6ddae64fb76c68ec594e4e62f4578eb4940d51d23033056a31bfeea2da4e4ad821e14070
|
7
|
+
data.tar.gz: f8943ad447f87aa33b8ae4facdfda3ae7368c8d3e9b3c7bfc1985ddfd97dd2654670620ed803ed52f38034c6c4bc7a49fdc0d8135be83f16504b2efcdb59ed50
|
data/Gemfile.rails-5-2
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
[](https://badge.fury.io/rb/active_record_upsert)
|
2
2
|
[](https://travis-ci.org/jesjos/active_record_upsert)
|
3
3
|
[](https://codeclimate.com/github/jesjos/active_record_upsert)
|
4
|
-
|
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
|
-
|
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 =
|
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)
|
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.
|
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-
|
12
|
+
date: 2018-09-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|