composite_primary_keys 12.0.2 → 12.0.7
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.
Potentially problematic release.
This version of composite_primary_keys might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/History.rdoc +30 -0
- data/README.rdoc +3 -2
- data/lib/composite_primary_keys.rb +57 -56
- data/lib/composite_primary_keys/active_model/attribute_assignment.rb +19 -0
- data/lib/composite_primary_keys/arel/sqlserver.rb +1 -3
- data/lib/composite_primary_keys/associations/through_association.rb +2 -1
- data/lib/composite_primary_keys/attribute_methods.rb +1 -1
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +13 -0
- data/lib/composite_primary_keys/base.rb +11 -0
- data/lib/composite_primary_keys/composite_arrays.rb +0 -8
- data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +24 -4
- data/lib/composite_primary_keys/connection_adapters/mysql/database_statements.rb +24 -0
- data/lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb +32 -11
- data/lib/composite_primary_keys/core.rb +1 -1
- data/lib/composite_primary_keys/persistence.rb +2 -2
- data/lib/composite_primary_keys/relation.rb +100 -25
- data/lib/composite_primary_keys/relation/batches.rb +1 -1
- data/lib/composite_primary_keys/relation/finder_methods.rb +1 -1
- data/lib/composite_primary_keys/relation/predicate_builder/association_query_value.rb +1 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/abstract_unit.rb +2 -1
- data/test/connections/databases.ci.yml +5 -2
- data/test/fixtures/article.rb +4 -0
- data/test/fixtures/articles.yml +4 -3
- data/test/fixtures/comment.rb +1 -3
- data/test/fixtures/comments.yml +10 -9
- data/test/fixtures/db_definitions/db2-create-tables.sql +0 -14
- data/test/fixtures/db_definitions/db2-drop-tables.sql +1 -3
- data/test/fixtures/db_definitions/mysql.sql +7 -44
- data/test/fixtures/db_definitions/oracle.drop.sql +3 -9
- data/test/fixtures/db_definitions/oracle.sql +12 -48
- data/test/fixtures/db_definitions/postgresql.sql +7 -44
- data/test/fixtures/db_definitions/sqlite.sql +6 -42
- data/test/fixtures/db_definitions/sqlserver.sql +5 -41
- data/test/fixtures/department.rb +8 -3
- data/test/fixtures/departments.yml +4 -4
- data/test/fixtures/readings.yml +2 -2
- data/test/fixtures/restaurants_suburbs.yml +1 -1
- data/test/fixtures/streets.yml +2 -2
- data/test/fixtures/suburbs.yml +2 -2
- data/test/fixtures/user.rb +3 -2
- data/test/test_associations.rb +30 -23
- data/test/test_create.rb +41 -18
- data/test/test_delete.rb +3 -3
- data/test/test_exists.rb +5 -5
- data/test/test_find.rb +21 -2
- data/test/test_habtm.rb +2 -2
- data/test/test_ids.rb +2 -6
- data/test/test_nested_attributes.rb +0 -57
- data/test/test_polymorphic.rb +29 -13
- data/test/test_preload.rb +4 -3
- data/test/test_serialize.rb +2 -2
- data/test/test_update.rb +19 -1
- metadata +11 -25
- data/test/fixtures/hack.rb +0 -5
- data/test/fixtures/hacks.yml +0 -3
- data/test/fixtures/pk_called_id.rb +0 -5
- data/test/fixtures/pk_called_ids.yml +0 -11
- data/test/fixtures/reference_code_using_composite_key_alias.rb +0 -8
- data/test/fixtures/reference_code_using_simple_key_alias.rb +0 -8
- data/test/fixtures/seat.rb +0 -5
- data/test/fixtures/seats.yml +0 -9
- data/test/fixtures/topic.rb +0 -6
- data/test/fixtures/topic_source.rb +0 -7
- data/test/test_aliases.rb +0 -18
- data/test/test_enum.rb +0 -21
- data/test/test_suite.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9669e29673330db679efb20ca257d87ce1cdad3d6fe69681a54ac706a0cd5f82
|
4
|
+
data.tar.gz: db2ba7fcc0f91b8cd6c54c177dd5ca9d7cb7d04b47f1ec42e43691283a1f16d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bfb9ac058f43b9e18499e7517029e41278272f91955058eaf87d3ecac4649906e84ee9e01a8b6466128cfe998bfe94eec6fbb7e9f0d1945a3e9a749a6990a93
|
7
|
+
data.tar.gz: 435cb41a8e3499508285444be01f8c585c747f98a0c6174353ac31f3ed147a8f165478dfce8bd975a10142d7357bdcee7121f9726ced186ceb2062e0bde36625
|
data/History.rdoc
CHANGED
@@ -1,3 +1,33 @@
|
|
1
|
+
== 12.0.7 (2021-02-15)
|
2
|
+
* Switch to GitHub actions (ta1kt0me)
|
3
|
+
* Fix MySQL/MariaDB query cache issue bug introduced in version 12.0.3 - see #539 (Charlie Savage)
|
4
|
+
* Do a better job of supporting composite keys with an auto incrementing field for
|
5
|
+
MySQL and MariaDB (Charlie Savage)
|
6
|
+
|
7
|
+
== 12.0.6 (2021-01-04)
|
8
|
+
* Fix issue when calling in_batches without a block (Charlie Savage)
|
9
|
+
|
10
|
+
== 12.0.5 (2020-12-31)
|
11
|
+
* Finally issue with SQLServer when tables are marked as exclude_output_inserted. See #535. (Charlie Savage)
|
12
|
+
|
13
|
+
== 12.0.4 (2020-12-30)
|
14
|
+
* Fix compatibility with Ruby Ruby 2.6 and below (ta1kt0me)
|
15
|
+
* Finally get SQLServer mass updates and deletes working (Charlie Savage)
|
16
|
+
* Fix MySQL mass updates and deletes that were broken by 12.0.3 (Charlie Savage)
|
17
|
+
|
18
|
+
== 12.0.3 (2020-11-11)
|
19
|
+
* Prevents infinite loops with gems which modify the 'attributes' method (Nicholas Guarino)
|
20
|
+
* Improve delete_all and update_all queries (Charlie Savage)
|
21
|
+
* Improve Oracle support (Charlie Savage)
|
22
|
+
* Improve SQL Server support. Note delete_all and update_all queries still do not work due to
|
23
|
+
quirks in SQL Server syntax (Charlie Savage)
|
24
|
+
* Improve support for polymorphic associations (Charlie Savage)
|
25
|
+
* Update fixtures and tests to include a model that uses an :id column as part of a composite
|
26
|
+
key (Charlie Savage)
|
27
|
+
* Fixed bug where id values were not correctly mapped between primary and foreign keys in associations (Charlie Savage)
|
28
|
+
* Cleanup how the gem is loaded (Charlie Savage)
|
29
|
+
* Remove older, unused or minimally used fixtures (Charlie Savage)
|
30
|
+
|
1
31
|
== 12.0.2 (2020-05-19)
|
2
32
|
* Remove deprecation warning for Ruby 2.7 due to keyword parameters (Alexandru Anca )
|
3
33
|
* Use sqlite for default in tests (Charlie Savage)
|
data/README.rdoc
CHANGED
@@ -113,7 +113,8 @@ divided into the following bundler groups:
|
|
113
113
|
Since it is likely you do not have all the above databases installed on your computer, you want to install just the
|
114
114
|
gems for your database. For example, to test postgresql you would install the appropriate gems like this:
|
115
115
|
|
116
|
-
bundler
|
116
|
+
bundler config set --local without "mysql oracle sqlite sqlserver"
|
117
|
+
bundler install
|
117
118
|
|
118
119
|
Once you have installed the appropriate gems, the next step is to create the test database. There is a rake
|
119
120
|
command for each database. Using our example:
|
@@ -132,7 +133,7 @@ Finally, to run tests:
|
|
132
133
|
|
133
134
|
rake postgresql:test
|
134
135
|
|
135
|
-
Travis build status: {<img src="https://travis-ci.
|
136
|
+
Travis build status: {<img src="https://travis-ci.com/composite-primary-keys/composite_primary_keys.svg" alt="Build Status" />}[https://travis-ci.com/composite-primary-keys/composite_primary_keys]
|
136
137
|
|
137
138
|
=== DB2
|
138
139
|
|
@@ -21,16 +21,17 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
$:.unshift(File.dirname(__FILE__)) unless
|
25
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
26
|
-
|
27
24
|
unless defined?(ActiveRecord)
|
28
25
|
require 'rubygems'
|
29
26
|
gem 'activerecord', '~>6.0.0'
|
30
27
|
require 'active_record'
|
31
28
|
end
|
32
29
|
|
33
|
-
#
|
30
|
+
# ActiveModel files we override
|
31
|
+
# _write_attribute
|
32
|
+
require 'active_model/attribute_assignment'
|
33
|
+
|
34
|
+
# ActiveRecord files we override
|
34
35
|
require 'active_record/attribute_methods'
|
35
36
|
require 'active_record/autosave_association'
|
36
37
|
require 'active_record/counter_cache'
|
@@ -61,58 +62,58 @@ require 'active_record/nested_attributes'
|
|
61
62
|
require 'active_record/connection_adapters/abstract/database_statements'
|
62
63
|
require 'active_record/connection_adapters/abstract_adapter'
|
63
64
|
require 'active_record/connection_adapters/postgresql/database_statements'
|
65
|
+
require 'active_record/connection_adapters/mysql/database_statements'
|
64
66
|
|
65
67
|
require 'active_record/relation/where_clause'
|
66
68
|
|
67
|
-
# CPK
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
#require 'composite_primary_keys/arel/sqlserver'
|
69
|
+
# CPK overrides
|
70
|
+
require_relative 'composite_primary_keys/active_model/attribute_assignment'
|
71
|
+
require_relative 'composite_primary_keys/attribute_methods'
|
72
|
+
require_relative 'composite_primary_keys/autosave_association'
|
73
|
+
require_relative 'composite_primary_keys/persistence'
|
74
|
+
require_relative 'composite_primary_keys/base'
|
75
|
+
require_relative 'composite_primary_keys/core'
|
76
|
+
require_relative 'composite_primary_keys/composite_arrays'
|
77
|
+
require_relative 'composite_primary_keys/composite_predicates'
|
78
|
+
require_relative 'composite_primary_keys/counter_cache'
|
79
|
+
require_relative 'composite_primary_keys/fixtures'
|
80
|
+
require_relative 'composite_primary_keys/reflection'
|
81
|
+
require_relative 'composite_primary_keys/relation'
|
82
|
+
require_relative 'composite_primary_keys/sanitization'
|
83
|
+
require_relative 'composite_primary_keys/transactions'
|
84
|
+
require_relative 'composite_primary_keys/version'
|
85
|
+
|
86
|
+
require_relative 'composite_primary_keys/associations/association'
|
87
|
+
require_relative 'composite_primary_keys/associations/association_scope'
|
88
|
+
require_relative 'composite_primary_keys/associations/foreign_association'
|
89
|
+
require_relative 'composite_primary_keys/associations/has_many_association'
|
90
|
+
require_relative 'composite_primary_keys/associations/has_many_through_association'
|
91
|
+
require_relative 'composite_primary_keys/associations/join_dependency'
|
92
|
+
require_relative 'composite_primary_keys/associations/preloader/association'
|
93
|
+
require_relative 'composite_primary_keys/associations/collection_association'
|
94
|
+
require_relative 'composite_primary_keys/associations/through_association'
|
95
|
+
|
96
|
+
require_relative 'composite_primary_keys/attribute_methods/primary_key'
|
97
|
+
require_relative 'composite_primary_keys/attribute_methods/read'
|
98
|
+
require_relative 'composite_primary_keys/attribute_methods/write'
|
99
|
+
require_relative 'composite_primary_keys/nested_attributes'
|
100
|
+
|
101
|
+
require_relative 'composite_primary_keys/connection_adapters/abstract/database_statements'
|
102
|
+
require_relative 'composite_primary_keys/connection_adapters/abstract_adapter'
|
103
|
+
#require_relative 'composite_primary_keys/connection_adapters/mysql/database_statements'
|
104
|
+
require_relative 'composite_primary_keys/connection_adapters/postgresql/database_statements'
|
105
|
+
require_relative 'composite_primary_keys/connection_adapters/sqlserver/database_statements'
|
106
|
+
|
107
|
+
require_relative 'composite_primary_keys/relation/batches'
|
108
|
+
require_relative 'composite_primary_keys/relation/where_clause'
|
109
|
+
require_relative 'composite_primary_keys/relation/calculations'
|
110
|
+
require_relative 'composite_primary_keys/relation/finder_methods'
|
111
|
+
require_relative 'composite_primary_keys/relation/predicate_builder/association_query_value'
|
112
|
+
require_relative 'composite_primary_keys/relation/query_methods'
|
113
|
+
|
114
|
+
require_relative 'composite_primary_keys/validations/uniqueness'
|
115
|
+
|
116
|
+
require_relative 'composite_primary_keys/composite_relation'
|
117
|
+
|
118
|
+
require_relative 'composite_primary_keys/arel/to_sql'
|
119
|
+
require_relative 'composite_primary_keys/arel/sqlserver'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module AttributeAssignment
|
3
|
+
def _assign_attribute(k, v)
|
4
|
+
# CPK. This is super ugly, but if a table has a composite key where one of the fields is named :id we need
|
5
|
+
# to handle it as a single value. Otherwise, we would call the id=(value) method which is expecting
|
6
|
+
# and array of values.
|
7
|
+
if k == 'id' && self.kind_of?(ActiveRecord::Base) && self.composite? && !self.column_for_attribute(k).null
|
8
|
+
self._write_attribute(k, v)
|
9
|
+
else
|
10
|
+
setter = :"#{k}="
|
11
|
+
if respond_to?(setter)
|
12
|
+
public_send(setter, v)
|
13
|
+
else
|
14
|
+
raise UnknownAttributeError.new(self, k)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -5,7 +5,8 @@ module ActiveRecord
|
|
5
5
|
|
6
6
|
def construct_join_attributes(*records)
|
7
7
|
# CPK
|
8
|
-
|
8
|
+
is_composite = self.source_reflection.polymorphic? ? source_reflection.active_record.composite? : source_reflection.klass.composite?
|
9
|
+
if is_composite
|
9
10
|
ensure_mutable
|
10
11
|
|
11
12
|
ids = records.map do |record|
|
@@ -1,6 +1,19 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module AttributeMethods
|
3
3
|
module PrimaryKey
|
4
|
+
module ClassMethods
|
5
|
+
def suppress_composite_primary_key(pk)
|
6
|
+
pk
|
7
|
+
# return pk unless pk.is_a?(Array)
|
8
|
+
#
|
9
|
+
# warn <<~WARNING
|
10
|
+
# WARNING: Active Record does not support composite primary key.
|
11
|
+
#
|
12
|
+
# #{table_name} has composite primary key. Composite primary key is ignored.
|
13
|
+
# WARNING
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
4
17
|
# Returns the primary key previous value.
|
5
18
|
def id_was
|
6
19
|
sync_with_transaction_state
|
@@ -89,6 +89,17 @@ module ActiveRecord
|
|
89
89
|
end
|
90
90
|
alias_method :ids, :id
|
91
91
|
|
92
|
+
# This is overridden purely for json serialization support. If the model is composite
|
93
|
+
# and one of the keys is id, then we don't want to call the id method, instead we want
|
94
|
+
# to get the id attribute value
|
95
|
+
def read_attribute_for_serialization(attribute)
|
96
|
+
if self.composite? && attribute == 'id'
|
97
|
+
read_attribute(attribute)
|
98
|
+
else
|
99
|
+
send(attribute)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
92
103
|
def ids_hash
|
93
104
|
self.class.primary_key.zip(ids).inject(Hash.new) do |hash, (key, value)|
|
94
105
|
hash[key] = value
|
@@ -49,14 +49,6 @@ module CompositePrimaryKeys
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
def in(other)
|
53
|
-
case other
|
54
|
-
when Arel::SelectManager
|
55
|
-
Arel::Nodes::In.new(self, other.ast)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
52
|
def to_s
|
61
53
|
# Doing this makes it easier to parse Base#[](attr_name)
|
62
54
|
map { |key| Utils.escape_string_key(key.to_s) }.join(ID_SEP)
|
@@ -5,11 +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
|
-
|
9
|
-
|
10
|
-
|
8
|
+
return id_value if id_value
|
9
|
+
|
10
|
+
if pk.is_a?(Array) && !value.empty?
|
11
|
+
# This is a CPK model and the query result is not empty. Thus we can figure out the new ids for each
|
12
|
+
# auto incremented field
|
13
|
+
pk.map {|key| value.first[key]}
|
14
|
+
elsif pk.is_a?(Array)
|
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
|
11
31
|
else
|
12
|
-
|
32
|
+
last_inserted_id(value)
|
13
33
|
end
|
14
34
|
end
|
15
35
|
end
|
@@ -0,0 +1,24 @@
|
|
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
|
@@ -3,19 +3,40 @@ module ActiveRecord
|
|
3
3
|
module SQLServer
|
4
4
|
module DatabaseStatements
|
5
5
|
def sql_for_insert(sql, pk, binds)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# sql.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT INSERTED.#{quoted_pk}"
|
10
|
-
quoted_pks = [pk].flatten.map {|pk| "INSERTED.#{SQLServer::Utils.extract_identifiers(pk).quoted}"}
|
11
|
-
sql.dup.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT #{quoted_pks.join(", ")}"
|
12
|
-
else
|
13
|
-
"#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident"
|
6
|
+
if pk.nil?
|
7
|
+
table_name = query_requires_identity_insert?(sql)
|
8
|
+
pk = primary_key(table_name)
|
14
9
|
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
sql = if pk && use_output_inserted? && !database_prefix_remote_server?
|
12
|
+
# CPK
|
13
|
+
#quoted_pk = SQLServer::Utils.extract_identifiers(pk).quoted
|
14
|
+
quoted_pk = Array(pk).map {|subkey| SQLServer::Utils.extract_identifiers(subkey).quoted}
|
15
|
+
|
16
|
+
table_name ||= get_table_name(sql)
|
17
|
+
exclude_output_inserted = exclude_output_inserted_table_name?(table_name, sql)
|
18
|
+
if exclude_output_inserted
|
19
|
+
id_sql_type = exclude_output_inserted.is_a?(TrueClass) ? "bigint" : exclude_output_inserted
|
20
|
+
# CPK
|
21
|
+
# <<~SQL.squish
|
22
|
+
# DECLARE @ssaIdInsertTable table (#{quoted_pk} #{id_sql_type});
|
23
|
+
# #{sql.dup.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT INSERTED.#{quoted_pk} INTO @ssaIdInsertTable"}
|
24
|
+
# SELECT CAST(#{quoted_pk.join(',')} AS #{id_sql_type}) FROM @ssaIdInsertTable
|
25
|
+
# SQL
|
26
|
+
<<~SQL.squish
|
27
|
+
DECLARE @ssaIdInsertTable table (#{quoted_pk.map {|subkey| "#{subkey} #{id_sql_type}"}.join(", ")});
|
28
|
+
#{sql.dup.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT INSERTED.#{quoted_pk.join(', INSERTED.')} INTO @ssaIdInsertTable"}
|
29
|
+
SELECT #{quoted_pk.map {|subkey| "CAST(#{subkey} AS #{id_sql_type}) #{subkey}"}.join(", ")} FROM @ssaIdInsertTable
|
30
|
+
SQL
|
31
|
+
else
|
32
|
+
# CPK
|
33
|
+
# sql.dup.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT INSERTED.#{quoted_pk}"
|
34
|
+
sql.dup.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT INSERTED.#{quoted_pk.join(', INSERTED.')}"
|
35
|
+
end
|
36
|
+
else
|
37
|
+
"#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident"
|
38
|
+
end
|
39
|
+
super
|
19
40
|
end
|
20
41
|
end
|
21
42
|
end
|
@@ -40,7 +40,7 @@ module ActiveRecord
|
|
40
40
|
|
41
41
|
record = statement.execute([id], connection)&.first
|
42
42
|
unless record
|
43
|
-
raise RecordNotFound.new("Couldn't find #{name} with '#{key}'=#{id}", name, key, id)
|
43
|
+
raise ::ActiveRecord::RecordNotFound.new("Couldn't find #{name} with '#{key}'=#{id}", name, key, id)
|
44
44
|
end
|
45
45
|
record
|
46
46
|
end
|
@@ -65,8 +65,8 @@ module ActiveRecord
|
|
65
65
|
)
|
66
66
|
|
67
67
|
# CPK
|
68
|
-
if self.composite?
|
69
|
-
self.id = self.id.zip(Array(new_id)).map {|id1, id2|
|
68
|
+
if self.composite?
|
69
|
+
self.id = self.id.zip(Array(new_id)).map {|id1, id2| id2.nil? ? id1 : id2}
|
70
70
|
else
|
71
71
|
self.id ||= new_id if self.class.primary_key
|
72
72
|
end
|