composite_primary_keys 9.0.6 → 9.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.
- checksums.yaml +4 -4
- data/History.rdoc +12 -0
- data/lib/composite_primary_keys/arel/sqlserver.rb +2 -2
- data/lib/composite_primary_keys/associations/collection_association.rb +17 -0
- data/lib/composite_primary_keys/associations/has_many_association.rb +19 -19
- data/lib/composite_primary_keys/base.rb +14 -14
- data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +23 -0
- data/lib/composite_primary_keys/version.rb +1 -1
- data/tasks/databases/oracle.rake +1 -1
- data/test/abstract_unit.rb +4 -0
- data/test/fixtures/db_definitions/mysql.sql +2 -2
- data/test/fixtures/employees.yml +18 -18
- data/test/test_preload.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 935a14ecfff54210eda1de87a8c012555dd8800b
|
4
|
+
data.tar.gz: aeeecd538f8856ca32f969cfade0dd6124164a34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a00381d95c99145e0a03e0e51051dfe69e09ac699316cfd9e9d2767103db7fa38ba40e00045d257bae284e1875a3dbcdb70e555c4d964b4f3f84ab6583c8e6ab
|
7
|
+
data.tar.gz: 7eb7dd0107eaa96f8c8adabcd04fe806bf9f40b2aef56469effbd7de01f338f32bed54be8dde25b02cea65364b3c3e3ac38d6f4f4060bdaa12d64c1297d5372b
|
data/History.rdoc
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== 9.0.7 (2017-05-22)
|
2
|
+
|
3
|
+
* Update sqlite3 to support deletes and updates (Charlie Savage)
|
4
|
+
* Specify version for sql server gem so it works with Rails 5.0 (Charlie Savage)
|
5
|
+
* Use `datetime` datatype to address Invalid default value for updated_at (Yasuo Honda)
|
6
|
+
* Fix ORA-00900 error when it attempts to execute blank statement (pustomytnyk)
|
7
|
+
* Override ActiveRecord::Associations::CollectionAssociation#ids_reader (pustomytnyk)
|
8
|
+
* Only define #primary_keys if #primary_keys=(value) is called (Charlie Savage)
|
9
|
+
* Change `timestamp` to `datetime` for MySQL as ActiveRecord timestamps type does (Oriol Collel)
|
10
|
+
* Fix incorrect case statement to get PK for SQLServer (Oriol Collel)
|
11
|
+
* Fixes random failures in test_preload_of_polymorphic_association (Boris Peterbarg)
|
12
|
+
|
1
13
|
== 9.0.6 (2017-01-08)
|
2
14
|
|
3
15
|
* Uncomment tests (Sammy Larbi)
|
@@ -6,6 +6,23 @@ module CompositePrimaryKeys
|
|
6
6
|
super
|
7
7
|
end
|
8
8
|
|
9
|
+
def ids_reader
|
10
|
+
if loaded?
|
11
|
+
load_target.map do |record|
|
12
|
+
if reflection.association_primary_key.is_a?(Array)
|
13
|
+
reflection.association_primary_key.map { |key| record.send(key) }
|
14
|
+
else
|
15
|
+
record.send(reflection.association_primary_key)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
else
|
19
|
+
@association_ids ||= (
|
20
|
+
column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}"
|
21
|
+
scope.pluck(column)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
9
26
|
def ids_writer(ids)
|
10
27
|
pk_type = reflection.primary_key_type
|
11
28
|
ids = Array(ids).reject(&:blank?)
|
@@ -18,29 +18,29 @@ module ActiveRecord
|
|
18
18
|
update_counter(-delete_count(method, scope))
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
scope.update_all(conds)
|
21
|
+
def delete_count(method, scope)
|
22
|
+
if method == :delete_all
|
23
|
+
scope.delete_all
|
24
|
+
else
|
25
|
+
# CPK
|
26
|
+
# scope.update_all(reflection.foreign_key => nil)
|
27
|
+
conds = Array(reflection.foreign_key).inject(Hash.new) do |mem, key|
|
28
|
+
mem[key] = nil
|
29
|
+
mem
|
32
30
|
end
|
31
|
+
scope.update_all(conds)
|
33
32
|
end
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
35
|
+
def foreign_key_present?
|
36
|
+
if reflection.klass.primary_key
|
37
|
+
# CPK
|
38
|
+
# owner.attribute_present?(reflection.association_primary_key)
|
39
|
+
Array(reflection.klass.primary_key).all? {|key| owner.attribute_present?(key)}
|
40
|
+
else
|
41
|
+
false
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
45
|
+
end
|
46
46
|
end
|
@@ -7,20 +7,6 @@ module ActiveRecord
|
|
7
7
|
NOT_IMPLEMENTED_YET = 'Not implemented for composite primary keys yet'
|
8
8
|
|
9
9
|
class << self
|
10
|
-
def primary_keys
|
11
|
-
unless defined?(@primary_keys)
|
12
|
-
reset_primary_keys
|
13
|
-
end
|
14
|
-
@primary_keys
|
15
|
-
end
|
16
|
-
|
17
|
-
# Don't like this method name, but its modeled after how AR does it
|
18
|
-
def reset_primary_keys
|
19
|
-
if self != base_class
|
20
|
-
self.primary_keys = base_class.primary_keys
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
10
|
alias_method :primary_key_without_composite_key_support=, :primary_key=
|
25
11
|
def primary_key=(keys)
|
26
12
|
unless keys.kind_of?(Array)
|
@@ -60,6 +46,20 @@ module ActiveRecord
|
|
60
46
|
end
|
61
47
|
|
62
48
|
module CompositeClassMethods
|
49
|
+
def primary_keys
|
50
|
+
unless defined?(@primary_keys)
|
51
|
+
reset_primary_keys
|
52
|
+
end
|
53
|
+
@primary_keys
|
54
|
+
end
|
55
|
+
|
56
|
+
# Don't like this method name, but its modeled after how AR does it
|
57
|
+
def reset_primary_keys
|
58
|
+
if self != base_class
|
59
|
+
self.primary_keys = base_class.primary_keys
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
63
|
def primary_key
|
64
64
|
primary_keys
|
65
65
|
end
|
@@ -0,0 +1,23 @@
|
|
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
|
data/tasks/databases/oracle.rake
CHANGED
@@ -14,7 +14,7 @@ namespace :oracle do
|
|
14
14
|
sql = File.read(schema)
|
15
15
|
|
16
16
|
sql.split(';').each do |command|
|
17
|
-
ActiveRecord::Base.connection.execute(command)
|
17
|
+
ActiveRecord::Base.connection.execute(command) unless command.blank?
|
18
18
|
end
|
19
19
|
|
20
20
|
ActiveRecord::Base.clear_all_connections!
|
data/test/abstract_unit.rb
CHANGED
@@ -18,6 +18,10 @@ puts "Loaded #{spec_name}"
|
|
18
18
|
# And now connect to the database
|
19
19
|
ActiveRecord::Base.establish_connection(spec)
|
20
20
|
|
21
|
+
if defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
|
22
|
+
require 'composite_primary_keys/connection_adapters/sqlite3_adapter'
|
23
|
+
end
|
24
|
+
|
21
25
|
# Tell active record about the configuration
|
22
26
|
ActiveRecord::Base.configurations[:test] = spec
|
23
27
|
|
@@ -39,8 +39,8 @@ create table tariffs (
|
|
39
39
|
tariff_id int not null,
|
40
40
|
start_date date not null,
|
41
41
|
amount integer(11) default null,
|
42
|
-
created_at
|
43
|
-
updated_at
|
42
|
+
created_at datetime,
|
43
|
+
updated_at datetime,
|
44
44
|
primary key (tariff_id, start_date)
|
45
45
|
);
|
46
46
|
|
data/test/fixtures/employees.yml
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
steve:
|
2
|
-
id: 1
|
3
|
-
department_id: 1
|
4
|
-
location_id: 1
|
5
|
-
|
6
|
-
jill:
|
7
|
-
id: 2
|
8
|
-
department_id: 1
|
9
|
-
location_id: 1
|
10
|
-
|
11
|
-
sarah:
|
12
|
-
id: 3
|
13
|
-
department_id: 2
|
14
|
-
location_id: 1
|
15
|
-
|
16
|
-
robert:
|
17
|
-
id: 4
|
18
|
-
department_id: 2
|
1
|
+
steve:
|
2
|
+
id: 1
|
3
|
+
department_id: 1
|
4
|
+
location_id: 1
|
5
|
+
|
6
|
+
jill:
|
7
|
+
id: 2
|
8
|
+
department_id: 1
|
9
|
+
location_id: 1
|
10
|
+
|
11
|
+
sarah:
|
12
|
+
id: 3
|
13
|
+
department_id: 2
|
14
|
+
location_id: 1
|
15
|
+
|
16
|
+
robert:
|
17
|
+
id: 4
|
18
|
+
department_id: 2
|
19
19
|
location_id: 1
|
data/test/test_preload.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('../abstract_unit', __FILE__)
|
2
2
|
|
3
3
|
class TestPreload < ActiveSupport::TestCase
|
4
|
-
fixtures :comments, :users, :employees, :groups
|
4
|
+
fixtures :comments, :users, :employees, :groups, :hacks
|
5
5
|
|
6
6
|
class UserForPreload < User
|
7
7
|
has_many :comments_with_include_condition, -> { where('person_type = ?', 'User')},
|
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: 9.0.
|
4
|
+
version: 9.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/composite_primary_keys/composite_relation.rb
|
114
114
|
- lib/composite_primary_keys/connection_adapters/abstract_adapter.rb
|
115
115
|
- lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb
|
116
|
+
- lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb
|
116
117
|
- lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb
|
117
118
|
- lib/composite_primary_keys/core.rb
|
118
119
|
- lib/composite_primary_keys/fixtures.rb
|
@@ -270,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
271
|
version: '0'
|
271
272
|
requirements: []
|
272
273
|
rubyforge_project:
|
273
|
-
rubygems_version: 2.6.
|
274
|
+
rubygems_version: 2.6.11
|
274
275
|
signing_key:
|
275
276
|
specification_version: 4
|
276
277
|
summary: Composite key support for ActiveRecord
|