composite_primary_keys 7.0.16 → 8.0.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 +600 -623
- data/lib/composite_primary_keys.rb +113 -115
- data/lib/composite_primary_keys/associations/association.rb +23 -23
- data/lib/composite_primary_keys/associations/association_scope.rb +73 -77
- data/lib/composite_primary_keys/associations/collection_association.rb +15 -0
- data/lib/composite_primary_keys/associations/has_many_association.rb +69 -56
- data/lib/composite_primary_keys/associations/has_many_through_association.rb +30 -28
- data/lib/composite_primary_keys/associations/join_dependency.rb +87 -89
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -22
- data/lib/composite_primary_keys/associations/preloader/association.rb +90 -78
- data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +19 -19
- data/lib/composite_primary_keys/associations/singular_association.rb +15 -0
- data/lib/composite_primary_keys/attribute_methods.rb +9 -0
- data/lib/composite_primary_keys/attribute_methods/dirty.rb +29 -26
- data/lib/composite_primary_keys/attribute_methods/read.rb +19 -34
- data/lib/composite_primary_keys/attribute_methods/write.rb +30 -36
- data/lib/composite_primary_keys/attribute_set/builder.rb +20 -0
- data/lib/composite_primary_keys/base.rb +135 -129
- data/lib/composite_primary_keys/composite_arrays.rb +30 -30
- data/lib/composite_primary_keys/composite_predicates.rb +50 -50
- data/lib/composite_primary_keys/composite_relation.rb +48 -48
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +2 -4
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +46 -60
- data/lib/composite_primary_keys/core.rb +69 -47
- data/lib/composite_primary_keys/fixtures.rb +22 -22
- data/lib/composite_primary_keys/persistence.rb +56 -60
- data/lib/composite_primary_keys/relation.rb +68 -56
- data/lib/composite_primary_keys/relation/calculations.rb +79 -75
- data/lib/composite_primary_keys/relation/finder_methods.rb +175 -196
- data/lib/composite_primary_keys/relation/query_methods.rb +40 -40
- data/lib/composite_primary_keys/sanitization.rb +52 -52
- data/lib/composite_primary_keys/validations/uniqueness.rb +36 -37
- data/lib/composite_primary_keys/version.rb +8 -8
- data/tasks/databases/oracle.rake +25 -25
- data/tasks/databases/sqlserver.rake +27 -40
- data/test/abstract_unit.rb +113 -113
- data/test/connections/databases.ci.yml +15 -15
- data/test/connections/databases.example.yml +18 -18
- data/test/connections/native_oracle/connection.rb +11 -11
- data/test/connections/native_oracle_enhanced/connection.rb +16 -16
- data/test/connections/native_sqlserver/connection.rb +11 -14
- data/test/fixtures/comment.rb +7 -7
- data/test/fixtures/db_definitions/db2-create-tables.sql +125 -126
- data/test/fixtures/db_definitions/db2-drop-tables.sql +18 -18
- data/test/fixtures/db_definitions/mysql.sql +207 -208
- data/test/fixtures/db_definitions/oracle.drop.sql +45 -45
- data/test/fixtures/db_definitions/oracle.sql +222 -223
- data/test/fixtures/db_definitions/postgresql.sql +209 -210
- data/test/fixtures/db_definitions/sqlite.sql +196 -197
- data/test/fixtures/db_definitions/sqlserver.drop.sql +91 -94
- data/test/fixtures/db_definitions/sqlserver.sql +225 -232
- data/test/fixtures/dorm.rb +2 -2
- data/test/fixtures/employee.rb +5 -5
- data/test/fixtures/membership.rb +6 -6
- data/test/fixtures/membership_statuses.yml +16 -16
- data/test/fixtures/memberships.yml +10 -10
- data/test/fixtures/product_tariffs.yml +14 -14
- data/test/fixtures/reference_code.rb +7 -7
- data/test/fixtures/restaurants_suburb.rb +2 -2
- data/test/fixtures/suburb.rb +5 -5
- data/test/fixtures/topic.rb +5 -5
- data/test/fixtures/topic_source.rb +6 -6
- data/test/fixtures/topic_sources.yml +3 -3
- data/test/fixtures/topics.yml +8 -8
- data/test/fixtures/users.yml +10 -10
- data/test/test_associations.rb +295 -275
- data/test/test_attribute_methods.rb +63 -63
- data/test/test_attributes.rb +60 -60
- data/test/test_calculations.rb +37 -42
- data/test/test_callbacks.rb +99 -99
- data/test/test_create.rb +112 -112
- data/test/test_delete.rb +148 -152
- data/test/test_delete_all.rb +28 -26
- data/test/test_dumpable.rb +15 -15
- data/test/test_enum.rb +21 -20
- data/test/test_equal.rb +26 -26
- data/test/test_find.rb +118 -118
- data/test/test_habtm.rb +113 -113
- data/test/test_nested_attributes.rb +124 -124
- data/test/test_polymorphic.rb +26 -26
- data/test/test_predicates.rb +40 -40
- data/test/test_santiago.rb +23 -23
- data/test/test_suite.rb +33 -34
- data/test/test_touch.rb +23 -23
- data/test/test_tutorial_example.rb +21 -21
- data/test/test_update.rb +71 -71
- metadata +9 -13
- data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -20
- data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +0 -59
- data/lib/composite_primary_keys/associations/join_dependency/join_part.rb +0 -39
- data/lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb +0 -46
- data/lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb +0 -17
- data/lib/composite_primary_keys/locking/optimistic.rb +0 -55
- data/test/test_optimistic.rb +0 -18
@@ -1,232 +1,225 @@
|
|
1
|
-
USE [composite_primary_keys_unittest];
|
2
|
-
go
|
3
|
-
|
4
|
-
CREATE TABLE topics (
|
5
|
-
id [int] IDENTITY(1000,1) NOT NULL,
|
6
|
-
name [varchar](50) default NULL,
|
7
|
-
feed_size [int] default NULL
|
8
|
-
);
|
9
|
-
go
|
10
|
-
|
11
|
-
CREATE TABLE topic_sources (
|
12
|
-
topic_id [int] NOT NULL,
|
13
|
-
platform [varchar](50) NOT NULL,
|
14
|
-
keywords [varchar](50) default NULL,
|
15
|
-
);
|
16
|
-
go
|
17
|
-
|
18
|
-
CREATE TABLE reference_types (
|
19
|
-
reference_type_id [int] IDENTITY(1000,1) NOT NULL,
|
20
|
-
type_label [varchar](50) NULL,
|
21
|
-
abbreviation [varchar](50) NULL,
|
22
|
-
description [varchar](50) NULL
|
23
|
-
);
|
24
|
-
go
|
25
|
-
|
26
|
-
CREATE TABLE reference_codes (
|
27
|
-
reference_type_id [int],
|
28
|
-
reference_code [int],
|
29
|
-
code_label [varchar](50) NULL,
|
30
|
-
abbreviation [varchar](50) NULL,
|
31
|
-
description [varchar](50) NULL
|
32
|
-
);
|
33
|
-
go
|
34
|
-
|
35
|
-
CREATE TABLE products (
|
36
|
-
id [int] IDENTITY(1000,1) NOT NULL,
|
37
|
-
name [varchar](50) NULL
|
38
|
-
);
|
39
|
-
go
|
40
|
-
|
41
|
-
CREATE TABLE tariffs (
|
42
|
-
[tariff_id] [int],
|
43
|
-
[start_date] [date],
|
44
|
-
[amount] [int] NULL
|
45
|
-
CONSTRAINT [tariffs_pk] PRIMARY KEY
|
46
|
-
( [tariff_id], [start_date] )
|
47
|
-
);
|
48
|
-
go
|
49
|
-
|
50
|
-
CREATE TABLE product_tariffs (
|
51
|
-
[product_id] [int],
|
52
|
-
[tariff_id] [int],
|
53
|
-
[tariff_start_date] [date]
|
54
|
-
CONSTRAINT [product_tariffs_pk] PRIMARY KEY
|
55
|
-
( [product_id], [tariff_id], [tariff_start_date] )
|
56
|
-
);
|
57
|
-
go
|
58
|
-
|
59
|
-
CREATE TABLE suburbs (
|
60
|
-
city_id [int],
|
61
|
-
suburb_id [int],
|
62
|
-
name varchar(50) not null,
|
63
|
-
CONSTRAINT [suburbs_pk] PRIMARY KEY
|
64
|
-
( [city_id], [suburb_id] )
|
65
|
-
);
|
66
|
-
go
|
67
|
-
|
68
|
-
CREATE TABLE streets (
|
69
|
-
id [int] IDENTITY(1000,1) NOT NULL,
|
70
|
-
city_id [int] NOT NULL,
|
71
|
-
suburb_id [int] NOT NULL,
|
72
|
-
name [varchar](50) NOT NULL
|
73
|
-
);
|
74
|
-
go
|
75
|
-
|
76
|
-
CREATE TABLE users (
|
77
|
-
id [int] IDENTITY(1000,1) NOT NULL,
|
78
|
-
name varchar(50) NOT NULL
|
79
|
-
);
|
80
|
-
go
|
81
|
-
|
82
|
-
CREATE TABLE articles (
|
83
|
-
id [int] IDENTITY(1000,1) NOT NULL,
|
84
|
-
name varchar(50) NOT NULL
|
85
|
-
);
|
86
|
-
go
|
87
|
-
|
88
|
-
CREATE TABLE readings (
|
89
|
-
id [int] PRIMARY KEY,
|
90
|
-
user_id [int] NOT NULL,
|
91
|
-
article_id [int] NOT NULL,
|
92
|
-
rating [int] NOT NULL
|
93
|
-
);
|
94
|
-
go
|
95
|
-
|
96
|
-
CREATE TABLE groups (
|
97
|
-
id [int] IDENTITY(1000,1) NOT NULL,
|
98
|
-
name [varchar](50) NOT NULL
|
99
|
-
);
|
100
|
-
go
|
101
|
-
|
102
|
-
CREATE TABLE memberships (
|
103
|
-
user_id [int] NOT NULL,
|
104
|
-
group_id [int] NOT NULL
|
105
|
-
CONSTRAINT [memberships_pk] PRIMARY KEY
|
106
|
-
( [user_id], [group_id] )
|
107
|
-
);
|
108
|
-
go
|
109
|
-
|
110
|
-
CREATE TABLE membership_statuses (
|
111
|
-
id [int] IDENTITY(1,1) NOT NULL,
|
112
|
-
user_id [int] not null,
|
113
|
-
group_id [int] not null,
|
114
|
-
status varchar(50) not null
|
115
|
-
);
|
116
|
-
go
|
117
|
-
|
118
|
-
CREATE TABLE departments (
|
119
|
-
department_id [int] NOT NULL,
|
120
|
-
location_id [int] NOT NULL
|
121
|
-
CONSTRAINT [departments_pk] PRIMARY KEY
|
122
|
-
( [department_id], [location_id] )
|
123
|
-
);
|
124
|
-
go
|
125
|
-
|
126
|
-
CREATE TABLE employees (
|
127
|
-
id [int] IDENTITY(1000,1) NOT NULL,
|
128
|
-
department_id [int] NULL,
|
129
|
-
location_id [int] NULL
|
130
|
-
);
|
131
|
-
go
|
132
|
-
|
133
|
-
CREATE TABLE comments (
|
134
|
-
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
|
135
|
-
person_id [int] NULL,
|
136
|
-
shown [int] NULL,
|
137
|
-
person_type varchar(100) NULL,
|
138
|
-
hack_id [int] NULL
|
139
|
-
);
|
140
|
-
go
|
141
|
-
|
142
|
-
CREATE TABLE hacks (
|
143
|
-
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
|
144
|
-
name [varchar](50) NOT NULL
|
145
|
-
);
|
146
|
-
go
|
147
|
-
|
148
|
-
CREATE TABLE restaurants (
|
149
|
-
franchise_id [int] NOT NULL,
|
150
|
-
store_id [int] NOT NULL,
|
151
|
-
name [varchar](100)
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
go
|
227
|
-
|
228
|
-
CREATE TABLE employees_groups (
|
229
|
-
employee_id [int] NOT NULL,
|
230
|
-
group_id [int] NOT NULL
|
231
|
-
);
|
232
|
-
go
|
1
|
+
USE [composite_primary_keys_unittest];
|
2
|
+
go
|
3
|
+
|
4
|
+
CREATE TABLE topics (
|
5
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
6
|
+
name [varchar](50) default NULL,
|
7
|
+
feed_size [int] default NULL
|
8
|
+
);
|
9
|
+
go
|
10
|
+
|
11
|
+
CREATE TABLE topic_sources (
|
12
|
+
topic_id [int] NOT NULL,
|
13
|
+
platform [varchar](50) NOT NULL,
|
14
|
+
keywords [varchar](50) default NULL,
|
15
|
+
);
|
16
|
+
go
|
17
|
+
|
18
|
+
CREATE TABLE reference_types (
|
19
|
+
reference_type_id [int] IDENTITY(1000,1) NOT NULL,
|
20
|
+
type_label [varchar](50) NULL,
|
21
|
+
abbreviation [varchar](50) NULL,
|
22
|
+
description [varchar](50) NULL
|
23
|
+
);
|
24
|
+
go
|
25
|
+
|
26
|
+
CREATE TABLE reference_codes (
|
27
|
+
reference_type_id [int],
|
28
|
+
reference_code [int],
|
29
|
+
code_label [varchar](50) NULL,
|
30
|
+
abbreviation [varchar](50) NULL,
|
31
|
+
description [varchar](50) NULL
|
32
|
+
);
|
33
|
+
go
|
34
|
+
|
35
|
+
CREATE TABLE products (
|
36
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
37
|
+
name [varchar](50) NULL
|
38
|
+
);
|
39
|
+
go
|
40
|
+
|
41
|
+
CREATE TABLE tariffs (
|
42
|
+
[tariff_id] [int],
|
43
|
+
[start_date] [date],
|
44
|
+
[amount] [int] NULL
|
45
|
+
CONSTRAINT [tariffs_pk] PRIMARY KEY
|
46
|
+
( [tariff_id], [start_date] )
|
47
|
+
);
|
48
|
+
go
|
49
|
+
|
50
|
+
CREATE TABLE product_tariffs (
|
51
|
+
[product_id] [int],
|
52
|
+
[tariff_id] [int],
|
53
|
+
[tariff_start_date] [date]
|
54
|
+
CONSTRAINT [product_tariffs_pk] PRIMARY KEY
|
55
|
+
( [product_id], [tariff_id], [tariff_start_date] )
|
56
|
+
);
|
57
|
+
go
|
58
|
+
|
59
|
+
CREATE TABLE suburbs (
|
60
|
+
city_id [int],
|
61
|
+
suburb_id [int],
|
62
|
+
name varchar(50) not null,
|
63
|
+
CONSTRAINT [suburbs_pk] PRIMARY KEY
|
64
|
+
( [city_id], [suburb_id] )
|
65
|
+
);
|
66
|
+
go
|
67
|
+
|
68
|
+
CREATE TABLE streets (
|
69
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
70
|
+
city_id [int] NOT NULL,
|
71
|
+
suburb_id [int] NOT NULL,
|
72
|
+
name [varchar](50) NOT NULL
|
73
|
+
);
|
74
|
+
go
|
75
|
+
|
76
|
+
CREATE TABLE users (
|
77
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
78
|
+
name varchar(50) NOT NULL
|
79
|
+
);
|
80
|
+
go
|
81
|
+
|
82
|
+
CREATE TABLE articles (
|
83
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
84
|
+
name varchar(50) NOT NULL
|
85
|
+
);
|
86
|
+
go
|
87
|
+
|
88
|
+
CREATE TABLE readings (
|
89
|
+
id [int] PRIMARY KEY,
|
90
|
+
user_id [int] NOT NULL,
|
91
|
+
article_id [int] NOT NULL,
|
92
|
+
rating [int] NOT NULL
|
93
|
+
);
|
94
|
+
go
|
95
|
+
|
96
|
+
CREATE TABLE groups (
|
97
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
98
|
+
name [varchar](50) NOT NULL
|
99
|
+
);
|
100
|
+
go
|
101
|
+
|
102
|
+
CREATE TABLE memberships (
|
103
|
+
user_id [int] NOT NULL,
|
104
|
+
group_id [int] NOT NULL
|
105
|
+
CONSTRAINT [memberships_pk] PRIMARY KEY
|
106
|
+
( [user_id], [group_id] )
|
107
|
+
);
|
108
|
+
go
|
109
|
+
|
110
|
+
CREATE TABLE membership_statuses (
|
111
|
+
id [int] IDENTITY(1,1) NOT NULL,
|
112
|
+
user_id [int] not null,
|
113
|
+
group_id [int] not null,
|
114
|
+
status varchar(50) not null
|
115
|
+
);
|
116
|
+
go
|
117
|
+
|
118
|
+
CREATE TABLE departments (
|
119
|
+
department_id [int] NOT NULL,
|
120
|
+
location_id [int] NOT NULL
|
121
|
+
CONSTRAINT [departments_pk] PRIMARY KEY
|
122
|
+
( [department_id], [location_id] )
|
123
|
+
);
|
124
|
+
go
|
125
|
+
|
126
|
+
CREATE TABLE employees (
|
127
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
128
|
+
department_id [int] NULL,
|
129
|
+
location_id [int] NULL
|
130
|
+
);
|
131
|
+
go
|
132
|
+
|
133
|
+
CREATE TABLE comments (
|
134
|
+
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
|
135
|
+
person_id [int] NULL,
|
136
|
+
shown [int] NULL,
|
137
|
+
person_type varchar(100) NULL,
|
138
|
+
hack_id [int] NULL
|
139
|
+
);
|
140
|
+
go
|
141
|
+
|
142
|
+
CREATE TABLE hacks (
|
143
|
+
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
|
144
|
+
name [varchar](50) NOT NULL
|
145
|
+
);
|
146
|
+
go
|
147
|
+
|
148
|
+
CREATE TABLE restaurants (
|
149
|
+
franchise_id [int] NOT NULL,
|
150
|
+
store_id [int] NOT NULL,
|
151
|
+
name [varchar](100)
|
152
|
+
CONSTRAINT [restaurants_pk] PRIMARY KEY CLUSTERED
|
153
|
+
( [franchise_id], [store_id] )
|
154
|
+
);
|
155
|
+
go
|
156
|
+
|
157
|
+
CREATE TABLE restaurants_suburbs (
|
158
|
+
franchise_id [int] NOT NULL,
|
159
|
+
store_id [int] NOT NULL,
|
160
|
+
city_id [int] NOT NULL,
|
161
|
+
suburb_id [int] NOT NULL
|
162
|
+
);
|
163
|
+
go
|
164
|
+
|
165
|
+
CREATE TABLE dorms (
|
166
|
+
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
|
167
|
+
);
|
168
|
+
go
|
169
|
+
|
170
|
+
CREATE TABLE rooms (
|
171
|
+
dorm_id [int] NOT NULL,
|
172
|
+
room_id [int] NOT NULL,
|
173
|
+
CONSTRAINT [rooms_pk] PRIMARY KEY CLUSTERED
|
174
|
+
( [dorm_id], [room_id] )
|
175
|
+
);
|
176
|
+
go
|
177
|
+
|
178
|
+
CREATE TABLE room_attributes (
|
179
|
+
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
|
180
|
+
name [varchar](50)
|
181
|
+
);
|
182
|
+
go
|
183
|
+
|
184
|
+
CREATE TABLE room_attribute_assignments (
|
185
|
+
dorm_id [int] NOT NULL,
|
186
|
+
room_id [int] NOT NULL,
|
187
|
+
room_attribute_id [int] NOT NULL
|
188
|
+
);
|
189
|
+
go
|
190
|
+
|
191
|
+
CREATE TABLE students (
|
192
|
+
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
|
193
|
+
);
|
194
|
+
go
|
195
|
+
|
196
|
+
CREATE TABLE room_assignments (
|
197
|
+
student_id [int] NOT NULL,
|
198
|
+
dorm_id [int] NOT NULL,
|
199
|
+
room_id [int] NOT NULL
|
200
|
+
);
|
201
|
+
go
|
202
|
+
|
203
|
+
CREATE TABLE seats (
|
204
|
+
flight_number [int] NOT NULL,
|
205
|
+
seat [int] NOT NULL,
|
206
|
+
customer [int]
|
207
|
+
CONSTRAINT [seats_pk] PRIMARY KEY
|
208
|
+
( [flight_number], [seat] )
|
209
|
+
);
|
210
|
+
go
|
211
|
+
|
212
|
+
CREATE TABLE capitols (
|
213
|
+
country varchar(450) NOT NULL,
|
214
|
+
city varchar(450) NOT NULL
|
215
|
+
CONSTRAINT [capitols_pk] PRIMARY KEY
|
216
|
+
( [country], [city] )
|
217
|
+
);
|
218
|
+
go
|
219
|
+
|
220
|
+
CREATE TABLE products_restaurants (
|
221
|
+
product_id [int] NOT NULL,
|
222
|
+
franchise_id [int] NOT NULL,
|
223
|
+
store_id [int] NOT NULL
|
224
|
+
);
|
225
|
+
go
|