composite_primary_keys 12.0.8 → 12.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +3 -0
- data/lib/composite_primary_keys.rb +0 -2
- data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +20 -5
- data/lib/composite_primary_keys/version.rb +1 -1
- metadata +2 -3
- data/lib/composite_primary_keys/connection_adapters/mysql/database_statements.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2465cca0fa83a628e24f3221e88095690295c99b2bf46818bd2ebd76df8300b5
|
4
|
+
data.tar.gz: a22c2b61575c26e23e51b314c05c158663c26ce7a9c64fb56019d596edc6a844
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3147006b49f98c3d1e88dbec56590fad63c13506634427361e14e06d611e75666c89c48c3e9151d174dc075d850a238285be6bc62739d8971d7bf190bc6e9db9
|
7
|
+
data.tar.gz: 34d811c5ab6afb7d5b4b9dc871b2df660f42abaf146ffc7faa60c9d4d2edfb8c1a8fa6e49b40488a6090a7bb64218fafb6b0e965744b4daa0d11c0fc34605abf
|
data/History.rdoc
CHANGED
@@ -62,7 +62,6 @@ require 'active_record/nested_attributes'
|
|
62
62
|
require 'active_record/connection_adapters/abstract/database_statements'
|
63
63
|
require 'active_record/connection_adapters/abstract_adapter'
|
64
64
|
require 'active_record/connection_adapters/postgresql/database_statements'
|
65
|
-
require 'active_record/connection_adapters/mysql/database_statements'
|
66
65
|
|
67
66
|
require 'active_record/relation/where_clause'
|
68
67
|
|
@@ -100,7 +99,6 @@ require_relative 'composite_primary_keys/nested_attributes'
|
|
100
99
|
|
101
100
|
require_relative 'composite_primary_keys/connection_adapters/abstract/database_statements'
|
102
101
|
require_relative 'composite_primary_keys/connection_adapters/abstract_adapter'
|
103
|
-
require_relative 'composite_primary_keys/connection_adapters/mysql/database_statements'
|
104
102
|
require_relative 'composite_primary_keys/connection_adapters/postgresql/database_statements'
|
105
103
|
require_relative 'composite_primary_keys/connection_adapters/sqlserver/database_statements'
|
106
104
|
|
@@ -5,16 +5,31 @@ module ActiveRecord
|
|
5
5
|
sql, binds = to_sql_and_binds(arel, binds)
|
6
6
|
value = exec_insert(sql, name, binds, pk, sequence_name)
|
7
7
|
|
8
|
+
return id_value if id_value
|
9
|
+
|
8
10
|
if pk.is_a?(Array) && !value.empty?
|
9
11
|
# This is a CPK model and the query result is not empty. Thus we can figure out the new ids for each
|
10
12
|
# auto incremented field
|
11
|
-
|
13
|
+
pk.map {|key| value.first[key]}
|
12
14
|
elsif pk.is_a?(Array)
|
13
|
-
# This is CPK, but we don't know what autoincremented fields were updated.
|
14
|
-
|
15
|
-
|
15
|
+
# This is CPK, but we don't know what autoincremented fields were updated.
|
16
|
+
result = Array.new(pk.size)
|
17
|
+
|
18
|
+
# Is there an autoincrementing field?
|
19
|
+
auto_key = pk.find do |key|
|
20
|
+
attribute = arel.ast.relation[key]
|
21
|
+
column = column_for_attribute(attribute)
|
22
|
+
if column.respond_to?(:auto_increment?)
|
23
|
+
column.auto_increment?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if auto_key
|
28
|
+
result[pk.index(auto_key)] = last_inserted_id(value)
|
29
|
+
end
|
30
|
+
result
|
16
31
|
else
|
17
|
-
|
32
|
+
last_inserted_id(value)
|
18
33
|
end
|
19
34
|
end
|
20
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 12.0.
|
4
|
+
version: 12.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -71,7 +71,6 @@ files:
|
|
71
71
|
- lib/composite_primary_keys/composite_relation.rb
|
72
72
|
- lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb
|
73
73
|
- lib/composite_primary_keys/connection_adapters/abstract_adapter.rb
|
74
|
-
- lib/composite_primary_keys/connection_adapters/mysql/database_statements.rb
|
75
74
|
- lib/composite_primary_keys/connection_adapters/postgresql/database_statements.rb
|
76
75
|
- lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb
|
77
76
|
- lib/composite_primary_keys/core.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module ConnectionAdapters
|
5
|
-
module MySQL
|
6
|
-
module DatabaseStatements
|
7
|
-
def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
|
8
|
-
sql, binds = to_sql_and_binds(arel, binds)
|
9
|
-
value = exec_insert(sql, name, binds, pk, sequence_name)
|
10
|
-
|
11
|
-
# CPK
|
12
|
-
if pk.is_a?(Array)
|
13
|
-
pk.map do |key|
|
14
|
-
column = column_for(arel.ast.relation.name, key)
|
15
|
-
column.auto_increment? ? last_inserted_id(value) : nil
|
16
|
-
end
|
17
|
-
else
|
18
|
-
id_value || last_inserted_id(value)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|