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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +600 -623
  3. data/lib/composite_primary_keys.rb +113 -115
  4. data/lib/composite_primary_keys/associations/association.rb +23 -23
  5. data/lib/composite_primary_keys/associations/association_scope.rb +73 -77
  6. data/lib/composite_primary_keys/associations/collection_association.rb +15 -0
  7. data/lib/composite_primary_keys/associations/has_many_association.rb +69 -56
  8. data/lib/composite_primary_keys/associations/has_many_through_association.rb +30 -28
  9. data/lib/composite_primary_keys/associations/join_dependency.rb +87 -89
  10. data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -22
  11. data/lib/composite_primary_keys/associations/preloader/association.rb +90 -78
  12. data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +19 -19
  13. data/lib/composite_primary_keys/associations/singular_association.rb +15 -0
  14. data/lib/composite_primary_keys/attribute_methods.rb +9 -0
  15. data/lib/composite_primary_keys/attribute_methods/dirty.rb +29 -26
  16. data/lib/composite_primary_keys/attribute_methods/read.rb +19 -34
  17. data/lib/composite_primary_keys/attribute_methods/write.rb +30 -36
  18. data/lib/composite_primary_keys/attribute_set/builder.rb +20 -0
  19. data/lib/composite_primary_keys/base.rb +135 -129
  20. data/lib/composite_primary_keys/composite_arrays.rb +30 -30
  21. data/lib/composite_primary_keys/composite_predicates.rb +50 -50
  22. data/lib/composite_primary_keys/composite_relation.rb +48 -48
  23. data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +2 -4
  24. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +46 -60
  25. data/lib/composite_primary_keys/core.rb +69 -47
  26. data/lib/composite_primary_keys/fixtures.rb +22 -22
  27. data/lib/composite_primary_keys/persistence.rb +56 -60
  28. data/lib/composite_primary_keys/relation.rb +68 -56
  29. data/lib/composite_primary_keys/relation/calculations.rb +79 -75
  30. data/lib/composite_primary_keys/relation/finder_methods.rb +175 -196
  31. data/lib/composite_primary_keys/relation/query_methods.rb +40 -40
  32. data/lib/composite_primary_keys/sanitization.rb +52 -52
  33. data/lib/composite_primary_keys/validations/uniqueness.rb +36 -37
  34. data/lib/composite_primary_keys/version.rb +8 -8
  35. data/tasks/databases/oracle.rake +25 -25
  36. data/tasks/databases/sqlserver.rake +27 -40
  37. data/test/abstract_unit.rb +113 -113
  38. data/test/connections/databases.ci.yml +15 -15
  39. data/test/connections/databases.example.yml +18 -18
  40. data/test/connections/native_oracle/connection.rb +11 -11
  41. data/test/connections/native_oracle_enhanced/connection.rb +16 -16
  42. data/test/connections/native_sqlserver/connection.rb +11 -14
  43. data/test/fixtures/comment.rb +7 -7
  44. data/test/fixtures/db_definitions/db2-create-tables.sql +125 -126
  45. data/test/fixtures/db_definitions/db2-drop-tables.sql +18 -18
  46. data/test/fixtures/db_definitions/mysql.sql +207 -208
  47. data/test/fixtures/db_definitions/oracle.drop.sql +45 -45
  48. data/test/fixtures/db_definitions/oracle.sql +222 -223
  49. data/test/fixtures/db_definitions/postgresql.sql +209 -210
  50. data/test/fixtures/db_definitions/sqlite.sql +196 -197
  51. data/test/fixtures/db_definitions/sqlserver.drop.sql +91 -94
  52. data/test/fixtures/db_definitions/sqlserver.sql +225 -232
  53. data/test/fixtures/dorm.rb +2 -2
  54. data/test/fixtures/employee.rb +5 -5
  55. data/test/fixtures/membership.rb +6 -6
  56. data/test/fixtures/membership_statuses.yml +16 -16
  57. data/test/fixtures/memberships.yml +10 -10
  58. data/test/fixtures/product_tariffs.yml +14 -14
  59. data/test/fixtures/reference_code.rb +7 -7
  60. data/test/fixtures/restaurants_suburb.rb +2 -2
  61. data/test/fixtures/suburb.rb +5 -5
  62. data/test/fixtures/topic.rb +5 -5
  63. data/test/fixtures/topic_source.rb +6 -6
  64. data/test/fixtures/topic_sources.yml +3 -3
  65. data/test/fixtures/topics.yml +8 -8
  66. data/test/fixtures/users.yml +10 -10
  67. data/test/test_associations.rb +295 -275
  68. data/test/test_attribute_methods.rb +63 -63
  69. data/test/test_attributes.rb +60 -60
  70. data/test/test_calculations.rb +37 -42
  71. data/test/test_callbacks.rb +99 -99
  72. data/test/test_create.rb +112 -112
  73. data/test/test_delete.rb +148 -152
  74. data/test/test_delete_all.rb +28 -26
  75. data/test/test_dumpable.rb +15 -15
  76. data/test/test_enum.rb +21 -20
  77. data/test/test_equal.rb +26 -26
  78. data/test/test_find.rb +118 -118
  79. data/test/test_habtm.rb +113 -113
  80. data/test/test_nested_attributes.rb +124 -124
  81. data/test/test_polymorphic.rb +26 -26
  82. data/test/test_predicates.rb +40 -40
  83. data/test/test_santiago.rb +23 -23
  84. data/test/test_suite.rb +33 -34
  85. data/test/test_touch.rb +23 -23
  86. data/test/test_tutorial_example.rb +21 -21
  87. data/test/test_update.rb +71 -71
  88. metadata +9 -13
  89. data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -20
  90. data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +0 -59
  91. data/lib/composite_primary_keys/associations/join_dependency/join_part.rb +0 -39
  92. data/lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb +0 -46
  93. data/lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb +0 -17
  94. data/lib/composite_primary_keys/locking/optimistic.rb +0 -55
  95. 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
- lock_version [int] DEFAULT 0
153
- CONSTRAINT [restaurants_pk] PRIMARY KEY CLUSTERED
154
- ( [franchise_id], [store_id] )
155
- );
156
- go
157
-
158
- CREATE TABLE restaurants_suburbs (
159
- franchise_id [int] NOT NULL,
160
- store_id [int] NOT NULL,
161
- city_id [int] NOT NULL,
162
- suburb_id [int] NOT NULL
163
- );
164
- go
165
-
166
- CREATE TABLE dorms (
167
- id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
168
- );
169
- go
170
-
171
- CREATE TABLE rooms (
172
- dorm_id [int] NOT NULL,
173
- room_id [int] NOT NULL,
174
- CONSTRAINT [rooms_pk] PRIMARY KEY CLUSTERED
175
- ( [dorm_id], [room_id] )
176
- );
177
- go
178
-
179
- CREATE TABLE room_attributes (
180
- id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
181
- name [varchar](50)
182
- );
183
- go
184
-
185
- CREATE TABLE room_attribute_assignments (
186
- dorm_id [int] NOT NULL,
187
- room_id [int] NOT NULL,
188
- room_attribute_id [int] NOT NULL
189
- );
190
- go
191
-
192
- CREATE TABLE students (
193
- id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
194
- );
195
- go
196
-
197
- CREATE TABLE room_assignments (
198
- student_id [int] NOT NULL,
199
- dorm_id [int] NOT NULL,
200
- room_id [int] NOT NULL
201
- );
202
- go
203
-
204
- CREATE TABLE seats (
205
- flight_number [int] NOT NULL,
206
- seat [int] NOT NULL,
207
- customer [int]
208
- CONSTRAINT [seats_pk] PRIMARY KEY
209
- ( [flight_number], [seat] )
210
- );
211
- go
212
-
213
- CREATE TABLE capitols (
214
- country varchar(450) NOT NULL,
215
- city varchar(450) NOT NULL
216
- CONSTRAINT [capitols_pk] PRIMARY KEY
217
- ( [country], [city] )
218
- );
219
- go
220
-
221
- CREATE TABLE products_restaurants (
222
- product_id [int] NOT NULL,
223
- franchise_id [int] NOT NULL,
224
- store_id [int] NOT NULL
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