composite_primary_keys 12.0.2 → 12.0.3
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 +13 -0
- data/README.rdoc +3 -2
- data/lib/composite_primary_keys.rb +56 -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 +8 -3
- data/lib/composite_primary_keys/connection_adapters/mysql/database_statements.rb +24 -0
- data/lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb +29 -11
- data/lib/composite_primary_keys/persistence.rb +2 -2
- data/lib/composite_primary_keys/relation.rb +36 -27
- 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 +3 -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 +6 -43
- 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 +15 -18
- data/test/test_delete.rb +3 -3
- data/test/test_exists.rb +5 -5
- data/test/test_find.rb +2 -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 +5 -19
- 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
@@ -6,7 +6,7 @@ module ActiveRecord
|
|
6
6
|
if associated_table.association_join_foreign_key.is_a?(Array)
|
7
7
|
if ids.is_a?(ActiveRecord::Relation)
|
8
8
|
ids.map do |id|
|
9
|
-
id.
|
9
|
+
associated_table.association_join_foreign_key.zip(id.id).to_h
|
10
10
|
end
|
11
11
|
else
|
12
12
|
[associated_table.association_join_foreign_key.zip(ids).to_h]
|
data/test/abstract_unit.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
spec_name = ENV['ADAPTER'] || '
|
2
|
-
require 'bundler
|
1
|
+
spec_name = ENV['ADAPTER'] || 'mysql'
|
2
|
+
require 'bundler'
|
3
3
|
require 'minitest/autorun'
|
4
4
|
|
5
|
+
Bundler.setup(:default, spec_name.to_sym)
|
5
6
|
Bundler.require(:default, spec_name.to_sym)
|
6
7
|
require 'composite_primary_keys'
|
7
8
|
|
data/test/fixtures/article.rb
CHANGED
@@ -2,5 +2,9 @@ class Article < ActiveRecord::Base
|
|
2
2
|
validates :id, uniqueness: true, numericality: true, allow_nil: true, allow_blank: true, on: :create
|
3
3
|
has_many :readings, :dependent => :delete_all
|
4
4
|
has_many :users, :through => :readings
|
5
|
+
|
6
|
+
has_many :comments, :dependent => :delete_all
|
7
|
+
has_many :employee_commentators, :through => :comments, :source => :person, :source_type => :employee
|
8
|
+
has_many :user_commentators, :through => :comments, :source => :person, :source_type => "User"
|
5
9
|
end
|
6
10
|
|
data/test/fixtures/articles.yml
CHANGED
data/test/fixtures/comment.rb
CHANGED
data/test/fixtures/comments.yml
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
-
|
1
|
+
employee_comment:
|
2
2
|
id: 1
|
3
|
+
article: first
|
3
4
|
person_id: 1
|
4
5
|
person_type: Employee
|
5
|
-
|
6
|
-
|
6
|
+
|
7
|
+
user_comment_1:
|
7
8
|
id: 2
|
9
|
+
article: second
|
8
10
|
person_id: 1
|
9
11
|
person_type: User
|
10
|
-
|
11
|
-
|
12
|
-
comment3:
|
12
|
+
|
13
|
+
user_comment_2:
|
13
14
|
id: 3
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
article: second
|
16
|
+
person_id: 2
|
17
|
+
person_type: User
|
@@ -1,17 +1,3 @@
|
|
1
|
-
CREATE TABLE topics (
|
2
|
-
id integer NOT NULL,
|
3
|
-
name varchar(50) default NULL,
|
4
|
-
feed_size integer default NULL,
|
5
|
-
PRIMARY KEY (id)
|
6
|
-
);
|
7
|
-
|
8
|
-
CREATE TABLE topic_sources (
|
9
|
-
topic_id integer NOT NULL,
|
10
|
-
platform varchar(50) NOT NULL,
|
11
|
-
keywords varchar(50) default NULL,
|
12
|
-
PRIMARY KEY (topic_id,platform)
|
13
|
-
);
|
14
|
-
|
15
1
|
CREATE TABLE reference_types (
|
16
2
|
reference_type_id integer NOT NULL generated by default as identity (start with 100, increment by 1, no cache),
|
17
3
|
type_label varchar(50) default NULL,
|
@@ -1,17 +1,3 @@
|
|
1
|
-
create table topics (
|
2
|
-
id int not null auto_increment,
|
3
|
-
name varchar(50) default null,
|
4
|
-
feed_size int default null,
|
5
|
-
primary key (id)
|
6
|
-
);
|
7
|
-
|
8
|
-
create table topic_sources (
|
9
|
-
topic_id int not null,
|
10
|
-
platform varchar(50) not null,
|
11
|
-
keywords varchar(50) default null,
|
12
|
-
primary key (topic_id,platform)
|
13
|
-
);
|
14
|
-
|
15
1
|
create table reference_types (
|
16
2
|
reference_type_id int not null auto_increment,
|
17
3
|
type_label varchar(50) default null,
|
@@ -52,7 +38,7 @@ create table product_tariffs (
|
|
52
38
|
);
|
53
39
|
|
54
40
|
create table suburbs (
|
55
|
-
city_id int not null,
|
41
|
+
city_id int not null auto_increment,
|
56
42
|
suburb_id int not null,
|
57
43
|
name varchar(50) not null,
|
58
44
|
primary key (city_id, suburb_id)
|
@@ -107,9 +93,9 @@ create table membership_statuses (
|
|
107
93
|
);
|
108
94
|
|
109
95
|
create table departments (
|
110
|
-
|
96
|
+
id int not null auto_increment,
|
111
97
|
location_id int not null,
|
112
|
-
primary key (
|
98
|
+
primary key (id, location_id)
|
113
99
|
);
|
114
100
|
|
115
101
|
create table employees (
|
@@ -122,16 +108,9 @@ create table employees (
|
|
122
108
|
|
123
109
|
create table comments (
|
124
110
|
id int not null auto_increment,
|
125
|
-
|
126
|
-
|
127
|
-
person_type varchar(100)
|
128
|
-
hack_id int default null,
|
129
|
-
primary key (id)
|
130
|
-
);
|
131
|
-
|
132
|
-
create table hacks (
|
133
|
-
id int not null auto_increment,
|
134
|
-
name varchar(50) not null,
|
111
|
+
article_id int not null,
|
112
|
+
person_id int not null,
|
113
|
+
person_type varchar(100) not null,
|
135
114
|
primary key (id)
|
136
115
|
);
|
137
116
|
|
@@ -184,13 +163,6 @@ create table room_assignments (
|
|
184
163
|
room_id int not null
|
185
164
|
);
|
186
165
|
|
187
|
-
create table seats (
|
188
|
-
flight_number int not null,
|
189
|
-
seat int not null,
|
190
|
-
customer int,
|
191
|
-
primary key (flight_number, seat)
|
192
|
-
);
|
193
|
-
|
194
166
|
create table capitols (
|
195
167
|
country varchar(100) not null,
|
196
168
|
city varchar(100) not null,
|
@@ -206,13 +178,4 @@ create table products_restaurants (
|
|
206
178
|
create table employees_groups (
|
207
179
|
employee_id int not null,
|
208
180
|
group_id int not null
|
209
|
-
);
|
210
|
-
|
211
|
-
create table pk_called_ids (
|
212
|
-
id integer not null,
|
213
|
-
reference_code int not null,
|
214
|
-
code_label varchar(50) default null,
|
215
|
-
abbreviation varchar(50) default null,
|
216
|
-
description varchar(50) default null,
|
217
|
-
primary key (id, reference_code)
|
218
181
|
);
|
@@ -1,6 +1,3 @@
|
|
1
|
-
drop table topics;
|
2
|
-
drop sequence topics_seq;
|
3
|
-
drop table topic_sources;
|
4
1
|
drop table reference_types;
|
5
2
|
drop sequence reference_types_seq;
|
6
3
|
drop table reference_codes;
|
@@ -9,6 +6,7 @@ drop sequence products_seq;
|
|
9
6
|
drop table tariffs;
|
10
7
|
drop table product_tariffs;
|
11
8
|
drop table suburbs;
|
9
|
+
drop sequence suburbs_city_id_seq;
|
12
10
|
drop table streets;
|
13
11
|
drop sequence streets_seq;
|
14
12
|
drop table users;
|
@@ -23,12 +21,11 @@ drop table memberships;
|
|
23
21
|
drop table membership_statuses;
|
24
22
|
drop sequence membership_statuses_seq;
|
25
23
|
drop table departments;
|
24
|
+
drop sequence departments_seq;
|
26
25
|
drop table employees;
|
27
26
|
drop sequence employees_seq;
|
28
27
|
drop table comments;
|
29
28
|
drop sequence comments_seq;
|
30
|
-
drop table hacks;
|
31
|
-
drop sequence hacks_seq;
|
32
29
|
drop table restaurants;
|
33
30
|
drop table restaurants_suburbs;
|
34
31
|
drop table dorms;
|
@@ -40,9 +37,6 @@ drop table room_attribute_assignments;
|
|
40
37
|
drop table room_assignments;
|
41
38
|
drop table students;
|
42
39
|
drop sequence students_seq;
|
43
|
-
drop table seats;
|
44
40
|
drop table capitols;
|
45
41
|
drop table products_restaurants;
|
46
|
-
drop table employees_groups;
|
47
|
-
drop table pk_called_ids;
|
48
|
-
drop sequence pk_called_ids_seq;
|
42
|
+
drop table employees_groups;
|
@@ -1,17 +1,3 @@
|
|
1
|
-
create sequence topics_seq start with 1000;
|
2
|
-
|
3
|
-
create table topics (
|
4
|
-
id number(11) primary key,
|
5
|
-
name varchar(50) default null,
|
6
|
-
feed_size number(11) default null
|
7
|
-
);
|
8
|
-
|
9
|
-
create table topic_sources (
|
10
|
-
topic_id number(11),
|
11
|
-
platform varchar(50),
|
12
|
-
keywords varchar(50) default null
|
13
|
-
);
|
14
|
-
|
15
1
|
create sequence reference_types_seq start with 1000;
|
16
2
|
|
17
3
|
create table reference_types (
|
@@ -52,9 +38,11 @@ create table product_tariffs (
|
|
52
38
|
constraint product_tariffs_pk primary key (product_id, tariff_id, tariff_start_date)
|
53
39
|
);
|
54
40
|
|
41
|
+
create sequence suburbs_city_id_seq start with 1000;
|
42
|
+
|
55
43
|
create table suburbs (
|
56
|
-
city_id number(11),
|
57
|
-
suburb_id number(11),
|
44
|
+
city_id number(11) default suburbs_city_id_seq.nextval not null,
|
45
|
+
suburb_id number(11) not null,
|
58
46
|
name varchar(50) not null,
|
59
47
|
constraint suburbs_pk primary key (city_id, suburb_id)
|
60
48
|
);
|
@@ -113,10 +101,12 @@ create table membership_statuses (
|
|
113
101
|
status varchar(50) not null
|
114
102
|
);
|
115
103
|
|
104
|
+
create sequence departments_seq start with 1000;
|
105
|
+
|
116
106
|
create table departments (
|
117
|
-
|
107
|
+
id number(11) not null,
|
118
108
|
location_id number(11) not null,
|
119
|
-
constraint departments_pk primary key (
|
109
|
+
constraint departments_pk primary key (id, location_id)
|
120
110
|
);
|
121
111
|
|
122
112
|
create sequence employees_seq start with 1000;
|
@@ -132,17 +122,9 @@ create sequence comments_seq start with 1000;
|
|
132
122
|
|
133
123
|
create table comments (
|
134
124
|
id number(11) not null primary key,
|
135
|
-
|
136
|
-
|
137
|
-
person_type varchar(100)
|
138
|
-
hack_id number(11) default null
|
139
|
-
);
|
140
|
-
|
141
|
-
create sequence hacks_seq start with 1000;
|
142
|
-
|
143
|
-
create table hacks (
|
144
|
-
id number(11) not null primary key,
|
145
|
-
name varchar(50) not null
|
125
|
+
article_id number(11) not null,
|
126
|
+
person_id number(11) not null,
|
127
|
+
person_type varchar(100) not null
|
146
128
|
);
|
147
129
|
|
148
130
|
create table restaurants (
|
@@ -200,13 +182,6 @@ create table room_assignments (
|
|
200
182
|
room_id number(11) not null
|
201
183
|
);
|
202
184
|
|
203
|
-
create table seats (
|
204
|
-
flight_number int not null,
|
205
|
-
seat int not null,
|
206
|
-
customer int,
|
207
|
-
primary key (flight_number, seat)
|
208
|
-
);
|
209
|
-
|
210
185
|
create table capitols (
|
211
186
|
country varchar(100) not null,
|
212
187
|
city varchar(100) not null,
|
@@ -222,15 +197,4 @@ create table products_restaurants (
|
|
222
197
|
create table employees_groups (
|
223
198
|
employee_id int not null,
|
224
199
|
group_id int not null
|
225
|
-
);
|
226
|
-
|
227
|
-
create sequence pk_called_ids_seq start with 1000;
|
228
|
-
|
229
|
-
create table pk_called_ids (
|
230
|
-
id int not null,
|
231
|
-
reference_code int not null,
|
232
|
-
code_label varchar(50) default null,
|
233
|
-
abbreviation varchar(50) default null,
|
234
|
-
description varchar(50) default null,
|
235
|
-
constraint pk_called_ids_pk primary key (id, reference_code)
|
236
|
-
);
|
200
|
+
);
|
@@ -1,17 +1,3 @@
|
|
1
|
-
create table topics (
|
2
|
-
id serial not null,
|
3
|
-
name varchar(50) default null,
|
4
|
-
feed_size int default null,
|
5
|
-
primary key (id)
|
6
|
-
);
|
7
|
-
|
8
|
-
create table topic_sources (
|
9
|
-
topic_id int not null,
|
10
|
-
platform varchar(50) not null,
|
11
|
-
keywords varchar(50) default null,
|
12
|
-
primary key (topic_id,platform)
|
13
|
-
);
|
14
|
-
|
15
1
|
create table reference_types (
|
16
2
|
reference_type_id serial not null,
|
17
3
|
type_label varchar(50) default null,
|
@@ -109,9 +95,9 @@ create table membership_statuses (
|
|
109
95
|
);
|
110
96
|
|
111
97
|
create table departments (
|
112
|
-
|
113
|
-
location_id
|
114
|
-
primary key (
|
98
|
+
id serial not null,
|
99
|
+
location_id int not null,
|
100
|
+
primary key (id, location_id)
|
115
101
|
);
|
116
102
|
|
117
103
|
create table employees (
|
@@ -124,16 +110,9 @@ create table employees (
|
|
124
110
|
|
125
111
|
create table comments (
|
126
112
|
id serial not null,
|
127
|
-
|
128
|
-
|
129
|
-
person_type varchar(100)
|
130
|
-
hack_id int default null,
|
131
|
-
primary key (id)
|
132
|
-
);
|
133
|
-
|
134
|
-
create table hacks (
|
135
|
-
id serial not null,
|
136
|
-
name varchar(50) not null,
|
113
|
+
article_id int not null references articles (id),
|
114
|
+
person_id int not null,
|
115
|
+
person_type varchar(100) not null,
|
137
116
|
primary key (id)
|
138
117
|
);
|
139
118
|
|
@@ -186,13 +165,6 @@ create table room_assignments (
|
|
186
165
|
room_id int not null
|
187
166
|
);
|
188
167
|
|
189
|
-
create table seats (
|
190
|
-
flight_number int not null,
|
191
|
-
seat int not null,
|
192
|
-
customer int,
|
193
|
-
primary key (flight_number, seat)
|
194
|
-
);
|
195
|
-
|
196
168
|
create table capitols (
|
197
169
|
country text not null,
|
198
170
|
city text not null,
|
@@ -208,13 +180,4 @@ create table products_restaurants (
|
|
208
180
|
create table employees_groups (
|
209
181
|
employee_id int not null,
|
210
182
|
group_id int not null
|
211
|
-
);
|
212
|
-
|
213
|
-
create table pk_called_ids (
|
214
|
-
id serial not null,
|
215
|
-
reference_code int not null,
|
216
|
-
code_label varchar(50) default null,
|
217
|
-
abbreviation varchar(50) default null,
|
218
|
-
description varchar(50) default null,
|
219
|
-
primary key (id, reference_code)
|
220
|
-
);
|
183
|
+
);
|
@@ -1,17 +1,3 @@
|
|
1
|
-
create table topics (
|
2
|
-
id int not null,
|
3
|
-
name varchar(50) default null,
|
4
|
-
feed_size int default null,
|
5
|
-
primary key (id)
|
6
|
-
);
|
7
|
-
|
8
|
-
create table topic_sources (
|
9
|
-
topic_id int not null,
|
10
|
-
platform varchar(50) not null,
|
11
|
-
keywords varchar(50) default null,
|
12
|
-
primary key (topic_id,platform)
|
13
|
-
);
|
14
|
-
|
15
1
|
create table reference_types (
|
16
2
|
reference_type_id integer primary key,
|
17
3
|
type_label varchar(50) default null,
|
@@ -101,9 +87,9 @@ create table membership_statuses (
|
|
101
87
|
);
|
102
88
|
|
103
89
|
create table departments (
|
104
|
-
|
90
|
+
id integer not null,
|
105
91
|
location_id integer not null,
|
106
|
-
primary key (
|
92
|
+
primary key (id, location_id)
|
107
93
|
);
|
108
94
|
|
109
95
|
create table employees (
|
@@ -115,15 +101,9 @@ create table employees (
|
|
115
101
|
|
116
102
|
create table comments (
|
117
103
|
id integer not null primary key autoincrement,
|
118
|
-
|
119
|
-
|
120
|
-
person_type varchar(100) null
|
121
|
-
hack_id int null
|
122
|
-
);
|
123
|
-
|
124
|
-
create table hacks (
|
125
|
-
id integer not null primary key autoincrement,
|
126
|
-
name varchar(50) not null
|
104
|
+
article_id int not null,
|
105
|
+
person_id int not null,
|
106
|
+
person_type varchar(100) not null
|
127
107
|
);
|
128
108
|
|
129
109
|
create table restaurants (
|
@@ -172,13 +152,6 @@ create table room_assignments (
|
|
172
152
|
room_id integer not null
|
173
153
|
);
|
174
154
|
|
175
|
-
create table seats (
|
176
|
-
flight_number integer not_null,
|
177
|
-
seat integer not_null,
|
178
|
-
customer integer,
|
179
|
-
primary key (flight_number, seat)
|
180
|
-
);
|
181
|
-
|
182
155
|
create table capitols (
|
183
156
|
country text not null,
|
184
157
|
city text not null,
|
@@ -194,13 +167,4 @@ create table products_restaurants (
|
|
194
167
|
create table employees_groups (
|
195
168
|
employee_id integer not null,
|
196
169
|
group_id integer not null
|
197
|
-
);
|
198
|
-
|
199
|
-
create table pk_called_ids (
|
200
|
-
id integer not null,
|
201
|
-
reference_code int not null,
|
202
|
-
code_label varchar(50) default null,
|
203
|
-
abbreviation varchar(50) default null,
|
204
|
-
description varchar(50) default null,
|
205
|
-
primary key (id, reference_code)
|
206
|
-
);
|
170
|
+
);
|