composite_primary_keys 11.3.1 → 12.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +17 -7
- data/README.rdoc +1 -0
- data/lib/composite_primary_keys.rb +1 -6
- data/lib/composite_primary_keys/arel/to_sql.rb +13 -13
- data/lib/composite_primary_keys/associations/association_scope.rb +4 -4
- data/lib/composite_primary_keys/associations/has_many_association.rb +2 -1
- data/lib/composite_primary_keys/associations/has_many_through_association.rb +0 -2
- data/lib/composite_primary_keys/associations/join_dependency.rb +9 -8
- data/lib/composite_primary_keys/associations/preloader/association.rb +28 -36
- data/lib/composite_primary_keys/attribute_methods.rb +2 -2
- data/lib/composite_primary_keys/attribute_methods/read.rb +11 -14
- data/lib/composite_primary_keys/attribute_methods/write.rb +8 -11
- data/lib/composite_primary_keys/base.rb +2 -2
- data/lib/composite_primary_keys/composite_arrays.rb +7 -50
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +1 -1
- data/lib/composite_primary_keys/connection_adapters/postgresql/database_statements.rb +1 -1
- data/lib/composite_primary_keys/core.rb +10 -14
- data/lib/composite_primary_keys/counter_cache.rb +4 -22
- data/lib/composite_primary_keys/fixtures.rb +5 -10
- data/lib/composite_primary_keys/nested_attributes.rb +6 -6
- data/lib/composite_primary_keys/persistence.rb +8 -8
- data/lib/composite_primary_keys/reflection.rb +3 -3
- data/lib/composite_primary_keys/relation.rb +39 -27
- data/lib/composite_primary_keys/relation/calculations.rb +15 -18
- data/lib/composite_primary_keys/relation/finder_methods.rb +56 -58
- data/lib/composite_primary_keys/relation/query_methods.rb +4 -3
- data/lib/composite_primary_keys/relation/where_clause.rb +2 -2
- data/lib/composite_primary_keys/sanitization.rb +37 -37
- data/lib/composite_primary_keys/validations/uniqueness.rb +2 -2
- data/lib/composite_primary_keys/version.rb +4 -4
- data/tasks/databases/mysql.rake +1 -1
- data/test/abstract_unit.rb +1 -5
- data/test/connections/databases.ci.yml +3 -0
- data/test/db_test.rb +53 -0
- data/test/fixtures/db_definitions/mysql.sql +1 -7
- data/test/fixtures/db_definitions/oracle.drop.sql +1 -3
- data/test/fixtures/db_definitions/oracle.sql +0 -8
- data/test/fixtures/db_definitions/postgresql.sql +0 -6
- data/test/fixtures/db_definitions/sqlite.sql +0 -6
- data/test/fixtures/db_definitions/sqlserver.sql +1 -8
- data/test/test_associations.rb +1 -1
- data/test/test_composite_arrays.rb +0 -14
- data/test/test_create.rb +12 -26
- data/test/test_find.rb +0 -8
- data/test/test_ids.rb +0 -3
- data/test/test_nested_attributes.rb +10 -10
- data/test/test_update.rb +1 -1
- metadata +9 -11
- data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +0 -20
- data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +0 -23
- data/test/fixtures/cpk_with_default_value.rb +0 -3
- data/test/fixtures/cpk_with_default_values.yml +0 -7
data/test/test_update.rb
CHANGED
@@ -28,7 +28,7 @@ class TestUpdate < ActiveSupport::TestCase
|
|
28
28
|
|
29
29
|
def test_update_attributes
|
30
30
|
testing_with do
|
31
|
-
assert(@first.
|
31
|
+
assert(@first.update(@klass_info[:update]))
|
32
32
|
assert(@first.reload)
|
33
33
|
@klass_info[:update].each_pair do |attr_name, new_value|
|
34
34
|
assert_equal(new_value, @first[attr_name])
|
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:
|
4
|
+
version: 12.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0.rc1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.0.rc1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,9 +112,7 @@ files:
|
|
112
112
|
- lib/composite_primary_keys/composite_relation.rb
|
113
113
|
- lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb
|
114
114
|
- lib/composite_primary_keys/connection_adapters/abstract_adapter.rb
|
115
|
-
- lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb
|
116
115
|
- lib/composite_primary_keys/connection_adapters/postgresql/database_statements.rb
|
117
|
-
- lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb
|
118
116
|
- lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb
|
119
117
|
- lib/composite_primary_keys/core.rb
|
120
118
|
- lib/composite_primary_keys/counter_cache.rb
|
@@ -147,14 +145,13 @@ files:
|
|
147
145
|
- test/connections/databases.ci.yml
|
148
146
|
- test/connections/databases.example.yml
|
149
147
|
- test/connections/databases.yml
|
148
|
+
- test/db_test.rb
|
150
149
|
- test/fixtures/article.rb
|
151
150
|
- test/fixtures/articles.yml
|
152
151
|
- test/fixtures/capitol.rb
|
153
152
|
- test/fixtures/capitols.yml
|
154
153
|
- test/fixtures/comment.rb
|
155
154
|
- test/fixtures/comments.yml
|
156
|
-
- test/fixtures/cpk_with_default_value.rb
|
157
|
-
- test/fixtures/cpk_with_default_values.yml
|
158
155
|
- test/fixtures/db_definitions/db2-create-tables.sql
|
159
156
|
- test/fixtures/db_definitions/db2-drop-tables.sql
|
160
157
|
- test/fixtures/db_definitions/mysql.sql
|
@@ -269,16 +266,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
269
266
|
version: 2.2.2
|
270
267
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
271
268
|
requirements:
|
272
|
-
- - "
|
269
|
+
- - ">"
|
273
270
|
- !ruby/object:Gem::Version
|
274
|
-
version:
|
271
|
+
version: 1.3.1
|
275
272
|
requirements: []
|
276
|
-
rubygems_version: 3.
|
273
|
+
rubygems_version: 3.0.3
|
277
274
|
signing_key:
|
278
275
|
specification_version: 4
|
279
276
|
summary: Composite key support for ActiveRecord
|
280
277
|
test_files:
|
281
278
|
- test/abstract_unit.rb
|
279
|
+
- test/db_test.rb
|
282
280
|
- test/README_tests.rdoc
|
283
281
|
- test/setup.rb
|
284
282
|
- test/test_aliases.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
class AbstractMysqlAdapter
|
4
|
-
def subquery_for(key, select)
|
5
|
-
subselect = select.clone
|
6
|
-
subselect.projections = [key]
|
7
|
-
|
8
|
-
# Materialize subquery by adding distinct
|
9
|
-
# to work with MySQL 5.7.6 which sets optimizer_switch='derived_merge=on'
|
10
|
-
subselect.distinct unless select.limit || select.offset || select.orders.any?
|
11
|
-
|
12
|
-
# CPK
|
13
|
-
#key_name = quote_column_name(key.name)
|
14
|
-
key_name = Array(key).map {|a_key| quote_column_name(a_key.name)}.join(',')
|
15
|
-
|
16
|
-
Arel::SelectManager.new(subselect.as("__active_record_temp")).project(Arel.sql(key_name))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
class SQLite3Adapter
|
4
|
-
def join_to_update(update, select, key)
|
5
|
-
if key.is_a?(::CompositePrimaryKeys::CompositeKeys)
|
6
|
-
subselect = subquery_for(key, select)
|
7
|
-
subselect_aliased = Arel::Nodes::TableAlias.new(subselect, 'cpk_inner')
|
8
|
-
cpk_subselect = Arel::SelectManager.new(subselect_aliased)
|
9
|
-
cpk_subselect.project('*')
|
10
|
-
key.each do |a_key|
|
11
|
-
where_expr = subselect_aliased[a_key.name].eq(update.ast.relation[a_key.name])
|
12
|
-
cpk_subselect.where(where_expr)
|
13
|
-
end
|
14
|
-
where_clause = Arel::Nodes::SqlLiteral.new("EXISTS (#{cpk_subselect.to_sql})")
|
15
|
-
update.where(where_clause)
|
16
|
-
else
|
17
|
-
super
|
18
|
-
end
|
19
|
-
end
|
20
|
-
alias join_to_delete join_to_update
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|