composite_primary_keys 11.0.3 → 11.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +5 -0
- data/README.rdoc +1 -1
- data/lib/composite_primary_keys.rb +2 -1
- data/lib/composite_primary_keys/arel/sqlserver.rb +2 -0
- data/lib/composite_primary_keys/associations/preloader/association.rb +0 -56
- data/lib/composite_primary_keys/autosave_association.rb +29 -1
- data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +6 -8
- data/lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb +23 -0
- data/lib/composite_primary_keys/counter_cache.rb +9 -4
- data/lib/composite_primary_keys/relation/finder_methods.rb +1 -1
- data/lib/composite_primary_keys/version.rb +2 -2
- data/test/connections/databases.yml +0 -1
- data/test/fixtures/db_definitions/mysql.sql +1 -10
- data/test/fixtures/db_definitions/oracle.drop.sql +0 -2
- data/test/fixtures/db_definitions/oracle.sql +2 -12
- data/test/fixtures/db_definitions/postgresql.sql +1 -10
- data/test/fixtures/db_definitions/sqlite.sql +2 -10
- data/test/fixtures/db_definitions/sqlserver.sql +2 -1
- data/test/fixtures/department.rb +8 -2
- data/test/fixtures/employee.rb +0 -5
- data/test/fixtures/employees.yml +10 -1
- data/test/test_associations.rb +31 -39
- data/test/test_counter_cache.rb +1 -1
- data/test/test_delete.rb +1 -1
- data/test/test_find.rb +2 -2
- data/test/test_preload.rb +7 -0
- data/test/test_suite.rb +1 -0
- metadata +5 -6
- data/lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb +0 -21
- data/test/fixtures/salary.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f55d6d32e63e96e3824998bbf0923818681cff80a944742a6a832908c560830e
|
4
|
+
data.tar.gz: 34c936d0f6eb9174bfabef659c7abf7774f2ce34251887d0408922251a06e06f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4edb592bacd34a108d44ca19706ad9012e048a3a81a449b6ee7726f07cf435acc19839599556db7fc24b2971315fc45966e093690285d1a30cd812e29f7ca48f
|
7
|
+
data.tar.gz: 42a0143eaa30e435beacf9e5be4e77f065af10a0dde691392bfa8599905da38a8f97213b3d67978d5c46ad33592f610674b33d55dd438e22e59f1476c7366219
|
data/History.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 11.1.0 (2018-11-14)
|
2
|
+
* Support ActiveRecord 5.2.1 (S1Artem Tselovalnikov, Caleb Buxton, Charlie Savage)
|
3
|
+
* Fix counter cache (Tomonori Murakami)
|
4
|
+
* Fix error on autosave has_one relations when the :primary_key option is set (Charlie Savage)
|
5
|
+
|
1
6
|
== 11.0.3 (2018-06-25)
|
2
7
|
* Fix overridden attribute readers and writers (Charlie Savage)
|
3
8
|
|
data/README.rdoc
CHANGED
@@ -20,7 +20,7 @@ Every major version of ActiveRecord has included numerous internal changes. As
|
|
20
20
|
CPK has to be rewritten for each version of ActiveRecord. To help keep
|
21
21
|
things straight, here is the mapping:
|
22
22
|
|
23
|
-
Version 11.x is designed to work with ActiveRecord 5.2.x
|
23
|
+
Version 11.x is designed to work with ActiveRecord 5.2.x
|
24
24
|
Version 10.x is designed to work with ActiveRecord 5.1.x
|
25
25
|
Version 9.x is designed to work with ActiveRecord 5.0.x
|
26
26
|
Version 8.x is designed to work with ActiveRecord 4.2.x
|
@@ -26,7 +26,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
26
26
|
|
27
27
|
unless defined?(ActiveRecord)
|
28
28
|
require 'rubygems'
|
29
|
-
gem 'activerecord', '~> 5.2.
|
29
|
+
gem 'activerecord', '~> 5.2.1'
|
30
30
|
require 'active_record'
|
31
31
|
end
|
32
32
|
|
@@ -101,6 +101,7 @@ require 'composite_primary_keys/nested_attributes'
|
|
101
101
|
require 'composite_primary_keys/connection_adapters/abstract_adapter'
|
102
102
|
require 'composite_primary_keys/connection_adapters/abstract_mysql_adapter'
|
103
103
|
require 'composite_primary_keys/connection_adapters/postgresql/database_statements'
|
104
|
+
require 'composite_primary_keys/connection_adapters/sqlserver/database_statements'
|
104
105
|
|
105
106
|
require 'composite_primary_keys/relation/batches'
|
106
107
|
require 'composite_primary_keys/relation/where_clause'
|
@@ -14,62 +14,6 @@ module ActiveRecord
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def associated_records_by_owner(preloader)
|
18
|
-
owners_map = owners_by_key
|
19
|
-
# CPK
|
20
|
-
# owner_keys = owners_map.keys.compact
|
21
|
-
owner_keys = if reflection.foreign_key.is_a?(Array)
|
22
|
-
owners.map do |owner|
|
23
|
-
Array(owner_key_name).map do |owner_key|
|
24
|
-
owner[owner_key]
|
25
|
-
end
|
26
|
-
end.compact.uniq
|
27
|
-
else
|
28
|
-
owners_map.keys.compact
|
29
|
-
end
|
30
|
-
|
31
|
-
# Each record may have multiple owners, and vice-versa
|
32
|
-
records_by_owner = owners.each_with_object({}) do |owner,h|
|
33
|
-
h[owner] = []
|
34
|
-
end
|
35
|
-
|
36
|
-
if owner_keys.any?
|
37
|
-
# Some databases impose a limit on the number of ids in a list (in Oracle it's 1000)
|
38
|
-
# Make several smaller queries if necessary or make one query if the adapter supports it
|
39
|
-
sliced = owner_keys.each_slice(klass.connection.in_clause_length || owner_keys.size)
|
40
|
-
|
41
|
-
records = load_slices sliced
|
42
|
-
records.each do |record, owner_key|
|
43
|
-
owners_map[owner_key].each do |owner|
|
44
|
-
records_by_owner[owner] << record
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
records_by_owner
|
50
|
-
end
|
51
|
-
|
52
|
-
def load_slices(slices)
|
53
|
-
@preloaded_records = slices.flat_map { |slice|
|
54
|
-
records_for(slice)
|
55
|
-
}
|
56
|
-
|
57
|
-
# CPK
|
58
|
-
# @preloaded_records.map { |record|
|
59
|
-
# key = record[association_key_name]
|
60
|
-
# key = key.to_s if key_conversion_required?
|
61
|
-
#
|
62
|
-
# [record, key]
|
63
|
-
# }
|
64
|
-
@preloaded_records.map { |record|
|
65
|
-
key = Array(association_key_name).map do |key_name|
|
66
|
-
record[key_name]
|
67
|
-
end.join(CompositePrimaryKeys::ID_SEP)
|
68
|
-
|
69
|
-
[record, key]
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
17
|
def owners_by_key
|
74
18
|
unless defined?(@owners_by_key)
|
75
19
|
@owners_by_key = owners.each_with_object({}) do |owner, h|
|
@@ -1,6 +1,34 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module AutosaveAssociation
|
3
|
-
|
3
|
+
def save_has_one_association(reflection)
|
4
|
+
association = association_instance_get(reflection.name)
|
5
|
+
record = association && association.load_target
|
6
|
+
|
7
|
+
if record && !record.destroyed?
|
8
|
+
autosave = reflection.options[:autosave]
|
9
|
+
|
10
|
+
if autosave && record.marked_for_destruction?
|
11
|
+
record.destroy
|
12
|
+
elsif autosave != false
|
13
|
+
# CPK
|
14
|
+
#key = reflection.options[:primary_key] ? send(reflection.options[:primary_key]) : id
|
15
|
+
key = reflection.options[:primary_key] ? self[reflection.options[:primary_key]] : id
|
16
|
+
|
17
|
+
if (autosave && record.changed_for_autosave?) || new_record? || record_changed?(reflection, record, key)
|
18
|
+
unless reflection.through_reflection
|
19
|
+
record[reflection.foreign_key] = key
|
20
|
+
if inverse_reflection = reflection.inverse_of
|
21
|
+
record.association(inverse_reflection.name).loaded!
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
saved = record.save(validate: !autosave)
|
26
|
+
raise ActiveRecord::Rollback if !saved && autosave
|
27
|
+
saved
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
4
32
|
|
5
33
|
def save_belongs_to_association(reflection)
|
6
34
|
association = association_instance_get(reflection.name)
|
@@ -2,20 +2,18 @@ module ActiveRecord
|
|
2
2
|
module ConnectionAdapters
|
3
3
|
class AbstractMysqlAdapter
|
4
4
|
def subquery_for(key, select)
|
5
|
-
|
6
|
-
|
5
|
+
subselect = select.clone
|
6
|
+
subselect.projections = [key]
|
7
7
|
|
8
8
|
# Materialize subquery by adding distinct
|
9
9
|
# to work with MySQL 5.7.6 which sets optimizer_switch='derived_merge=on'
|
10
|
-
|
11
|
-
|
12
|
-
subselect = Arel::SelectManager.new(select.engine)
|
10
|
+
subselect.distinct unless select.limit || select.offset || select.orders.any?
|
13
11
|
|
14
12
|
# CPK
|
15
|
-
#
|
16
|
-
|
13
|
+
#key_name = quote_column_name(key.name)
|
14
|
+
key_name = Array(key).map {|a_key| quote_column_name(a_key.name)}.join(',')
|
17
15
|
|
18
|
-
subselect.
|
16
|
+
Arel::SelectManager.new(subselect.as("__active_record_temp")).project(Arel.sql(key_name))
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module DatabaseStatements
|
5
|
+
def sql_for_insert(sql, pk, id_value, sequence_name, binds)
|
6
|
+
sql = if pk && self.class.use_output_inserted
|
7
|
+
# CPK
|
8
|
+
# quoted_pk = SQLServer::Utils.extract_identifiers(pk).quoted
|
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"
|
14
|
+
end
|
15
|
+
|
16
|
+
# CPK
|
17
|
+
# super
|
18
|
+
[sql, binds]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -11,17 +11,22 @@ module ActiveRecord
|
|
11
11
|
end
|
12
12
|
|
13
13
|
if touch
|
14
|
-
|
14
|
+
names = touch if touch != true
|
15
|
+
touch_updates = touch_attributes_with_time(*names)
|
15
16
|
updates << sanitize_sql_for_assignment(touch_updates) unless touch_updates.empty?
|
16
17
|
end
|
17
18
|
|
19
|
+
if id.is_a?(Relation) && self == id.klass
|
20
|
+
relation = id
|
18
21
|
# CPK
|
19
|
-
|
22
|
+
elsif primary_key.is_a?(Array)
|
20
23
|
predicate = self.cpk_id_predicate(self.arel_table, self.primary_key, id)
|
21
|
-
unscoped.where(predicate)
|
24
|
+
relation = unscoped.where!(predicate)
|
22
25
|
else
|
23
|
-
unscoped.where(primary_key => id)
|
26
|
+
relation = unscoped.where!(primary_key => id)
|
24
27
|
end
|
28
|
+
|
29
|
+
relation.update_all updates.join(", ")
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
@@ -116,16 +116,7 @@ create table employees (
|
|
116
116
|
id int not null auto_increment,
|
117
117
|
department_id int default null,
|
118
118
|
location_id int default null,
|
119
|
-
|
120
|
-
);
|
121
|
-
|
122
|
-
create table salaries (
|
123
|
-
id int not null auto_increment,
|
124
|
-
employee_id int,
|
125
|
-
location_id int,
|
126
|
-
year int not null,
|
127
|
-
month int not null,
|
128
|
-
value int default null,
|
119
|
+
name varchar(50) default null,
|
129
120
|
primary key (id)
|
130
121
|
);
|
131
122
|
|
@@ -23,8 +23,6 @@ drop table memberships;
|
|
23
23
|
drop table membership_statuses;
|
24
24
|
drop sequence membership_statuses_seq;
|
25
25
|
drop table departments;
|
26
|
-
drop table salaries;
|
27
|
-
drop sequence salaries_seq;
|
28
26
|
drop table employees;
|
29
27
|
drop sequence employees_seq;
|
30
28
|
drop table comments;
|
@@ -124,18 +124,8 @@ create sequence employees_seq start with 1000;
|
|
124
124
|
create table employees (
|
125
125
|
id number(11) not null primary key,
|
126
126
|
department_id number(11) default null,
|
127
|
-
location_id number(11) default null
|
128
|
-
)
|
129
|
-
|
130
|
-
create sequence salaries_seq start with 1000;
|
131
|
-
|
132
|
-
create table salaries (
|
133
|
-
id number(11) not null primary key,
|
134
|
-
employee_id number(11) default null,
|
135
|
-
location_id number(11) default null,
|
136
|
-
year int not null,
|
137
|
-
month int not null,
|
138
|
-
value int default null
|
127
|
+
location_id number(11) default null,
|
128
|
+
name varchar(50) not null
|
139
129
|
);
|
140
130
|
|
141
131
|
create sequence comments_seq start with 1000;
|
@@ -118,16 +118,7 @@ create table employees (
|
|
118
118
|
id serial not null,
|
119
119
|
department_id int default null,
|
120
120
|
location_id int default null,
|
121
|
-
|
122
|
-
);
|
123
|
-
|
124
|
-
create table salaries (
|
125
|
-
id serial not null,
|
126
|
-
employee_id int,
|
127
|
-
location_id int,
|
128
|
-
year int not null,
|
129
|
-
month int not null,
|
130
|
-
value int default null,
|
121
|
+
name text not null,
|
131
122
|
primary key (id)
|
132
123
|
);
|
133
124
|
|
@@ -109,16 +109,8 @@ create table departments (
|
|
109
109
|
create table employees (
|
110
110
|
id integer not null primary key autoincrement,
|
111
111
|
department_id integer null,
|
112
|
-
location_id integer null
|
113
|
-
)
|
114
|
-
|
115
|
-
create table salaries (
|
116
|
-
id integer not null primary key autoincrement,
|
117
|
-
employee_id integer,
|
118
|
-
location_id integer,
|
119
|
-
year int not null,
|
120
|
-
month int not null,
|
121
|
-
value int default null
|
112
|
+
location_id integer null,
|
113
|
+
name varchar(50) not null
|
122
114
|
);
|
123
115
|
|
124
116
|
create table comments (
|
@@ -111,7 +111,8 @@ CREATE TABLE departments (
|
|
111
111
|
CREATE TABLE employees (
|
112
112
|
id [int] IDENTITY(1000,1) NOT NULL,
|
113
113
|
department_id [int] NULL,
|
114
|
-
location_id [int] NULL
|
114
|
+
location_id [int] NULL,
|
115
|
+
name [varchar](50) NOT NULL
|
115
116
|
);
|
116
117
|
|
117
118
|
CREATE TABLE comments (
|
data/test/fixtures/department.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
class Department < ActiveRecord::Base
|
2
2
|
self.primary_keys = :department_id, :location_id
|
3
|
-
has_many :employees,
|
4
|
-
|
3
|
+
has_many :employees,
|
4
|
+
# We intentionally redefine primary key for test purposes. #455
|
5
|
+
:primary_key => [:department_id, :location_id],
|
6
|
+
:foreign_key => [:department_id, :location_id]
|
7
|
+
has_one :head, :class_name => 'Employee', :autosave => true, :dependent => :delete,
|
8
|
+
# We intentionally redefine primary key for test purposes. #455
|
9
|
+
:primary_key => [:department_id, :location_id],
|
10
|
+
:foreign_key => [:department_id, :location_id]
|
5
11
|
end
|
data/test/fixtures/employee.rb
CHANGED
@@ -2,9 +2,4 @@ class Employee < ActiveRecord::Base
|
|
2
2
|
belongs_to :department, :foreign_key => [:department_id, :location_id]
|
3
3
|
has_many :comments, :as => :person
|
4
4
|
has_and_belongs_to_many :groups
|
5
|
-
has_many :salaries, :primary_key => [:id, :location_id],
|
6
|
-
:foreign_key => [:employee_id, :location_id]
|
7
|
-
has_one :one_salary, :class_name => "Salary",
|
8
|
-
:primary_key => [:id, :location_id],
|
9
|
-
:foreign_key => [:employee_id, :location_id]
|
10
5
|
end
|
data/test/fixtures/employees.yml
CHANGED
@@ -2,18 +2,27 @@ steve:
|
|
2
2
|
id: 1
|
3
3
|
department_id: 1
|
4
4
|
location_id: 1
|
5
|
+
name: Steve
|
5
6
|
|
6
7
|
jill:
|
7
8
|
id: 2
|
8
9
|
department_id: 1
|
9
10
|
location_id: 1
|
11
|
+
name: Jill
|
10
12
|
|
11
13
|
sarah:
|
12
14
|
id: 3
|
13
15
|
department_id: 2
|
14
16
|
location_id: 1
|
17
|
+
name: Sarah
|
15
18
|
|
16
19
|
robert:
|
17
20
|
id: 4
|
18
21
|
department_id: 2
|
19
|
-
location_id: 1
|
22
|
+
location_id: 1
|
23
|
+
name: Robert
|
24
|
+
|
25
|
+
mindy:
|
26
|
+
department_id: 3
|
27
|
+
location_id: 2
|
28
|
+
name: Mindy
|
data/test/test_associations.rb
CHANGED
@@ -82,18 +82,27 @@ class TestAssociations < ActiveSupport::TestCase
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_has_one_association_primary_key_and_foreign_key_are_present
|
85
|
-
|
86
|
-
|
85
|
+
department = departments(:human_resources)
|
86
|
+
|
87
|
+
assert_equal(1, department.employees.count)
|
88
|
+
assert_equal('Mindy', department.employees[0].name)
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
+
head = department.create_head(name: 'Rick')
|
91
|
+
assert_equal(department.department_id, head.department_id)
|
92
|
+
assert_equal(department.location_id, head.location_id)
|
90
93
|
|
91
|
-
|
92
|
-
|
93
|
-
assert_equal(
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
department.reload
|
95
|
+
assert_equal(1, department.employees.count)
|
96
|
+
assert_equal('Rick', department.employees[0].name)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_has_one_autosave
|
100
|
+
department = departments(:engineering)
|
101
|
+
assert_equal('Sarah', department.head.name)
|
102
|
+
|
103
|
+
department.head.name = 'Sarah1'
|
104
|
+
department.save!
|
105
|
+
assert_equal('Sarah1', department.head.name)
|
97
106
|
end
|
98
107
|
|
99
108
|
def test_has_many_association_is_not_cached_to_where_it_returns_the_wrong_ones
|
@@ -107,35 +116,18 @@ class TestAssociations < ActiveSupport::TestCase
|
|
107
116
|
end
|
108
117
|
|
109
118
|
def test_has_many_association_primary_key_and_foreign_key_are_present
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
assert_equal(
|
119
|
-
assert_equal(
|
120
|
-
assert_equal(
|
121
|
-
assert_equal(
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_belongs_to_association_primary_key_and_foreign_key_are_present
|
125
|
-
bogus_foreign_key = 2_500_000
|
126
|
-
salary_01 = Salary.new(
|
127
|
-
year: 2015,
|
128
|
-
month: 1,
|
129
|
-
employee_id: bogus_foreign_key,
|
130
|
-
location_id: 1
|
131
|
-
)
|
132
|
-
salary_01.save!
|
133
|
-
employee_01 = salary_01.create_employee
|
134
|
-
employee_01.reload
|
135
|
-
|
136
|
-
assert_equal(salary_01.employee_id, employee_01.id, "Generated id used")
|
137
|
-
assert_not_equal(bogus_foreign_key, employee_01.id, "Bogus value ignored")
|
138
|
-
assert_equal(1, employee_01.location_id)
|
119
|
+
department = departments(:accounting)
|
120
|
+
assert_equal(2, department.employees.count)
|
121
|
+
assert_equal('Steve', department.employees[0].name)
|
122
|
+
assert_equal('Jill', department.employees[1].name)
|
123
|
+
|
124
|
+
head = department.employees.create(name: 'Rick')
|
125
|
+
|
126
|
+
department.reload
|
127
|
+
assert_equal(3, department.employees.count)
|
128
|
+
assert_equal('Steve', department.employees[0].name)
|
129
|
+
assert_equal('Jill', department.employees[1].name)
|
130
|
+
assert_equal('Rick', department.employees[2].name)
|
139
131
|
end
|
140
132
|
|
141
133
|
def test_find_includes_product_tariffs_product
|
data/test/test_counter_cache.rb
CHANGED
data/test/test_delete.rb
CHANGED
@@ -105,7 +105,7 @@ class TestDelete < ActiveSupport::TestCase
|
|
105
105
|
|
106
106
|
def test_create_destroy_has_and_belongs_to_many_on_non_cpk
|
107
107
|
records_before = ActiveRecord::Base.connection.execute('select * from employees_groups')
|
108
|
-
employee = Employee.create
|
108
|
+
employee = Employee.create!(department_id: 3, location_id: 2, name: 'Jon')
|
109
109
|
employee.groups << Group.create(name: 'test')
|
110
110
|
employee.destroy!
|
111
111
|
records_after = ActiveRecord::Base.connection.execute('select * from employees_groups')
|
data/test/test_find.rb
CHANGED
@@ -102,13 +102,13 @@ class TestFind < ActiveSupport::TestCase
|
|
102
102
|
def test_find_by_all_associations
|
103
103
|
departments = Department.all
|
104
104
|
employees = Employee.where(:department => departments)
|
105
|
-
assert_equal(
|
105
|
+
assert_equal(5, employees.to_a.count)
|
106
106
|
end
|
107
107
|
|
108
108
|
def test_expand_all
|
109
109
|
departments = Department.all
|
110
110
|
employees = Employee.where(:department => departments)
|
111
|
-
assert_equal(
|
111
|
+
assert_equal(5, employees.count)
|
112
112
|
end
|
113
113
|
|
114
114
|
def test_find_one_with_params_id
|
data/test/test_preload.rb
CHANGED
@@ -91,4 +91,11 @@ class TestPreload < ActiveSupport::TestCase
|
|
91
91
|
assert_equal(1, employees.first.groups_2.size)
|
92
92
|
assert_equal(2, employees.second.groups_2.size)
|
93
93
|
end
|
94
|
+
|
95
|
+
def test_preload_settings_inversion
|
96
|
+
user = User.preload(:readings).find_by!(:name => 'Santiago')
|
97
|
+
assert_equal(2, user.readings.count)
|
98
|
+
reading = user.readings.first
|
99
|
+
assert_equal(true, reading.association(:user).loaded?)
|
100
|
+
end
|
94
101
|
end
|
data/test/test_suite.rb
CHANGED
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: 11.0
|
4
|
+
version: 11.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-14 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: 5.2.
|
19
|
+
version: 5.2.1
|
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: 5.2.
|
26
|
+
version: 5.2.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,7 +113,7 @@ files:
|
|
113
113
|
- lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb
|
114
114
|
- lib/composite_primary_keys/connection_adapters/postgresql/database_statements.rb
|
115
115
|
- lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb
|
116
|
-
- lib/composite_primary_keys/connection_adapters/
|
116
|
+
- lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb
|
117
117
|
- lib/composite_primary_keys/core.rb
|
118
118
|
- lib/composite_primary_keys/counter_cache.rb
|
119
119
|
- lib/composite_primary_keys/fixtures.rb
|
@@ -200,7 +200,6 @@ files:
|
|
200
200
|
- test/fixtures/room_attribute_assignments.yml
|
201
201
|
- test/fixtures/room_attributes.yml
|
202
202
|
- test/fixtures/rooms.yml
|
203
|
-
- test/fixtures/salary.rb
|
204
203
|
- test/fixtures/seat.rb
|
205
204
|
- test/fixtures/seats.yml
|
206
205
|
- test/fixtures/street.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
class SQLServerAdapter
|
4
|
-
def sql_for_insert(sql, pk, id_value, sequence_name, binds)
|
5
|
-
sql = if pk && self.class.use_output_inserted
|
6
|
-
# CPK
|
7
|
-
# quoted_pk = SQLServer::Utils.extract_identifiers(pk).quoted
|
8
|
-
# sql.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT INSERTED.#{quoted_pk}"
|
9
|
-
quoted_pks = [pk].flatten.map {|pk| "INSERTED.#{SQLServer::Utils.extract_identifiers(pk).quoted}"}
|
10
|
-
sql.dup.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT #{quoted_pks.join(", ")}"
|
11
|
-
else
|
12
|
-
"#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident"
|
13
|
-
end
|
14
|
-
|
15
|
-
# CPK
|
16
|
-
# super
|
17
|
-
[sql, binds]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|