composite_primary_keys 6.0.8 → 7.0.0
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 +2 -8
- data/lib/composite_primary_keys.rb +9 -11
- data/lib/composite_primary_keys/active_model/dirty.rb +14 -0
- data/lib/composite_primary_keys/associations/association_scope.rb +30 -32
- data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +1 -2
- data/lib/composite_primary_keys/associations/has_many_association.rb +13 -14
- data/lib/composite_primary_keys/associations/has_many_through_association.rb +88 -0
- data/lib/composite_primary_keys/associations/join_dependency.rb +23 -15
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +3 -3
- data/lib/composite_primary_keys/associations/preloader/association.rb +37 -21
- data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +9 -3
- data/lib/composite_primary_keys/base.rb +0 -1
- data/lib/composite_primary_keys/composite_predicates.rb +11 -34
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +6 -5
- data/lib/composite_primary_keys/core.rb +28 -16
- data/lib/composite_primary_keys/model_schema.rb +15 -0
- data/lib/composite_primary_keys/nested_attributes.rb +8 -10
- data/lib/composite_primary_keys/persistence.rb +28 -29
- data/lib/composite_primary_keys/relation.rb +86 -16
- data/lib/composite_primary_keys/relation/finder_methods.rb +113 -59
- data/lib/composite_primary_keys/version.rb +2 -2
- data/test/abstract_unit.rb +7 -8
- data/test/fixtures/db_definitions/db2-create-tables.sql +13 -20
- data/test/fixtures/db_definitions/db2-drop-tables.sql +13 -14
- data/test/fixtures/db_definitions/mysql.sql +0 -7
- data/test/fixtures/db_definitions/oracle.drop.sql +0 -1
- data/test/fixtures/db_definitions/oracle.sql +0 -6
- data/test/fixtures/db_definitions/postgresql.sql +0 -7
- data/test/fixtures/db_definitions/sqlite.sql +24 -30
- data/test/fixtures/db_definitions/sqlserver.drop.sql +1 -4
- data/test/fixtures/db_definitions/sqlserver.sql +7 -16
- data/test/fixtures/dorm.rb +2 -2
- data/test/fixtures/suburb.rb +2 -2
- data/test/test_associations.rb +1 -2
- data/test/test_attribute_methods.rb +3 -3
- data/test/test_delete.rb +3 -5
- data/test/test_equal.rb +5 -5
- data/test/test_find.rb +2 -14
- data/test/test_predicates.rb +2 -2
- data/test/test_santiago.rb +1 -1
- data/test/test_serialize.rb +1 -1
- data/test/test_suite.rb +0 -1
- data/test/test_tutorial_example.rb +3 -3
- metadata +9 -32
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +0 -17
- data/lib/composite_primary_keys/composite_relation.rb +0 -44
- data/lib/composite_primary_keys/locking/optimistic.rb +0 -51
- data/test/fixtures/model_with_callback.rb +0 -39
- data/test/fixtures/model_with_callbacks.yml +0 -3
- data/test/test_callbacks.rb +0 -36
- data/test/test_dumpable.rb +0 -15
- data/test/test_optimistic.rb +0 -18
@@ -28,7 +28,7 @@ CREATE TABLE tariffs (
|
|
28
28
|
[tariff_id] [int],
|
29
29
|
[start_date] [date],
|
30
30
|
[amount] [int] NULL
|
31
|
-
CONSTRAINT [tariffs_pk] PRIMARY KEY
|
31
|
+
CONSTRAINT [tariffs_pk] PRIMARY KEY
|
32
32
|
( [tariff_id], [start_date] )
|
33
33
|
);
|
34
34
|
go
|
@@ -88,7 +88,7 @@ go
|
|
88
88
|
CREATE TABLE memberships (
|
89
89
|
user_id [int] NOT NULL,
|
90
90
|
group_id [int] NOT NULL
|
91
|
-
CONSTRAINT [memberships_pk] PRIMARY KEY
|
91
|
+
CONSTRAINT [memberships_pk] PRIMARY KEY
|
92
92
|
( [user_id], [group_id] )
|
93
93
|
);
|
94
94
|
go
|
@@ -133,9 +133,8 @@ go
|
|
133
133
|
CREATE TABLE restaurants (
|
134
134
|
franchise_id [int] NOT NULL,
|
135
135
|
store_id [int] NOT NULL,
|
136
|
-
name [varchar](100)
|
137
|
-
|
138
|
-
CONSTRAINT [restaurants_pk] PRIMARY KEY CLUSTERED
|
136
|
+
name [varchar](100)
|
137
|
+
CONSTRAINT [restaurants_pk] PRIMARY KEY CLUSTERED
|
139
138
|
( [franchise_id], [store_id] )
|
140
139
|
);
|
141
140
|
go
|
@@ -156,7 +155,7 @@ go
|
|
156
155
|
CREATE TABLE rooms (
|
157
156
|
dorm_id [int] NOT NULL,
|
158
157
|
room_id [int] NOT NULL,
|
159
|
-
CONSTRAINT [rooms_pk] PRIMARY KEY CLUSTERED
|
158
|
+
CONSTRAINT [rooms_pk] PRIMARY KEY CLUSTERED
|
160
159
|
( [dorm_id], [room_id] )
|
161
160
|
);
|
162
161
|
go
|
@@ -198,7 +197,7 @@ go
|
|
198
197
|
CREATE TABLE capitols (
|
199
198
|
country varchar(450) NOT NULL,
|
200
199
|
city varchar(450) NOT NULL
|
201
|
-
CONSTRAINT [capitols_pk] PRIMARY KEY
|
200
|
+
CONSTRAINT [capitols_pk] PRIMARY KEY
|
202
201
|
( [country], [city] )
|
203
202
|
);
|
204
203
|
go
|
@@ -208,12 +207,4 @@ CREATE TABLE products_restaurants (
|
|
208
207
|
franchise_id [int] NOT NULL,
|
209
208
|
store_id [int] NOT NULL
|
210
209
|
);
|
211
|
-
go
|
212
|
-
|
213
|
-
CREATE TABLE model_with_callbacks (
|
214
|
-
reference_type_id [int],
|
215
|
-
reference_code [int],
|
216
|
-
CONSTRAINT [model_with_callbacks_pk] PRIMARY KEY
|
217
|
-
( [reference_type_id], [reference_code] )
|
218
|
-
);
|
219
|
-
go
|
210
|
+
go
|
data/test/fixtures/dorm.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
class Dorm < ActiveRecord::Base
|
2
|
-
has_many :rooms, -> {
|
3
|
-
end
|
2
|
+
has_many :rooms, -> {includes(:room_attributes)}, :primary_key => [:id]
|
3
|
+
end
|
data/test/fixtures/suburb.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Suburb < ActiveRecord::Base
|
2
2
|
self.primary_keys = :city_id, :suburb_id
|
3
3
|
has_many :streets, :foreign_key => [:city_id, :suburb_id]
|
4
|
-
has_many :first_streets, -> {
|
4
|
+
has_many :first_streets, -> {where("streets.name = 'First Street'")},
|
5
5
|
:foreign_key => [:city_id, :suburb_id], :class_name => 'Street'
|
6
|
-
end
|
6
|
+
end
|
data/test/test_associations.rb
CHANGED
@@ -260,7 +260,7 @@ class TestAssociations < ActiveSupport::TestCase
|
|
260
260
|
end
|
261
261
|
|
262
262
|
def test_limitable_reflections
|
263
|
-
memberships = Membership.includes(:statuses).where("membership_statuses.status = ?", 'Active').limit(1)
|
263
|
+
memberships = Membership.includes(:statuses).where("membership_statuses.status = ?", 'Active').references(:membership_statuses).limit(1)
|
264
264
|
assert_equal(1, memberships.length)
|
265
265
|
assert_equal([1,1], memberships[0].id)
|
266
266
|
end
|
@@ -271,5 +271,4 @@ class TestAssociations < ActiveSupport::TestCase
|
|
271
271
|
associations = group.association_cache[:memberships]
|
272
272
|
assert_equal(false, associations.send('foreign_key_present?'))
|
273
273
|
end
|
274
|
-
|
275
274
|
end
|
@@ -11,7 +11,7 @@ class TestAttributeMethods < ActiveSupport::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_read_attribute_with_composite_keys
|
14
|
-
ref_code = ReferenceCode.find(1, 1)
|
14
|
+
ref_code = ReferenceCode.find([1, 1])
|
15
15
|
assert_equal(1, ref_code.id.first)
|
16
16
|
assert_equal(1, ref_code.id.last)
|
17
17
|
assert_equal('Mr', ref_code.abbreviation)
|
@@ -24,7 +24,7 @@ class TestAttributeMethods < ActiveSupport::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_to_key_with_composite_keys
|
27
|
-
ref_code = ReferenceCode.find(1, 1)
|
27
|
+
ref_code = ReferenceCode.find([1, 1])
|
28
28
|
assert_equal(1, ref_code.to_key.first)
|
29
29
|
assert_equal(1, ref_code.to_key.last)
|
30
30
|
end
|
@@ -46,7 +46,7 @@ class TestAttributeMethods < ActiveSupport::TestCase
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_to_key_with_composite_key_destroyed
|
49
|
-
ref_code = ReferenceCode.find(1, 1)
|
49
|
+
ref_code = ReferenceCode.find([1, 1])
|
50
50
|
ref_code.destroy
|
51
51
|
assert_equal([1,1], ref_code.to_key)
|
52
52
|
end
|
data/test/test_delete.rb
CHANGED
@@ -90,13 +90,11 @@ class TestDelete < ActiveSupport::TestCase
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_destroy_has_and_belongs_to_many_on_non_cpk
|
93
|
+
steve = employees(:steve)
|
93
94
|
records_before = ActiveRecord::Base.connection.execute("select * from employees_groups").count
|
94
|
-
|
95
|
-
employee.groups << Group.create(name: 'test')
|
96
|
-
employees_groups_count = employee.groups.count
|
97
|
-
employee.destroy!
|
95
|
+
steve.destroy
|
98
96
|
records_after = ActiveRecord::Base.connection.execute("select * from employees_groups").count
|
99
|
-
assert_equal
|
97
|
+
assert_equal records_after, records_before - steve.groups.count
|
100
98
|
end
|
101
99
|
|
102
100
|
def test_delete_not_destroy_on_cpk
|
data/test/test_equal.rb
CHANGED
@@ -4,7 +4,7 @@ class TestEqual < ActiveSupport::TestCase
|
|
4
4
|
fixtures :capitols
|
5
5
|
|
6
6
|
def test_new
|
7
|
-
assert_not_equal(Capitol.new
|
7
|
+
assert_not_equal(Capitol.new, Capitol.new)
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_same_new
|
@@ -13,14 +13,14 @@ class TestEqual < ActiveSupport::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_same
|
16
|
-
first = Capitol.find('Canada', 'Ottawa')
|
17
|
-
second = Capitol.find('Canada', 'Ottawa')
|
16
|
+
first = Capitol.find(['Canada', 'Ottawa'])
|
17
|
+
second = Capitol.find(['Canada', 'Ottawa'])
|
18
18
|
assert_equal(first, second)
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_different
|
22
|
-
first = Capitol.find('Mexico', 'Mexico City')
|
23
|
-
second = Capitol.find('Canada', 'Ottawa')
|
22
|
+
first = Capitol.find(['Mexico', 'Mexico City'])
|
23
|
+
second = Capitol.find(['Canada', 'Ottawa'])
|
24
24
|
assert_not_equal(first, second)
|
25
25
|
end
|
26
26
|
end
|
data/test/test_find.rb
CHANGED
@@ -22,12 +22,6 @@ class TestFind < ActiveSupport::TestCase
|
|
22
22
|
assert_equal([1,3], ref_code.id)
|
23
23
|
end
|
24
24
|
|
25
|
-
def test_find_one_string
|
26
|
-
ref_code = ReferenceCode.find('1,3')
|
27
|
-
assert_kind_of(ReferenceCode, ref_code)
|
28
|
-
assert_equal([1,3], ref_code.id)
|
29
|
-
end
|
30
|
-
|
31
25
|
def test_find_some
|
32
26
|
ref_codes = ReferenceCode.find([1,3], [2,1])
|
33
27
|
assert_kind_of(Array, ref_codes)
|
@@ -71,14 +65,8 @@ class TestFind < ActiveSupport::TestCase
|
|
71
65
|
ref_type_quoted = "#{connection.quote_table_name('reference_codes')}.#{connection.quote_column_name('reference_type_id')}"
|
72
66
|
ref_code_quoted = "#{connection.quote_table_name('reference_codes')}.#{connection.quote_column_name('reference_code')}"
|
73
67
|
|
74
|
-
|
75
|
-
|
76
|
-
else
|
77
|
-
expected = "Couldn't find ReferenceCode with ID=999,999 WHERE #{ref_type_quoted} = 999 AND #{ref_code_quoted} = 999"
|
78
|
-
end
|
79
|
-
|
80
|
-
assert_equal(with_quoted_identifiers(expected),
|
81
|
-
error.message)
|
68
|
+
expected = "Couldn't find all ReferenceCodes with 'reference_type_id,reference_code': (999, 999) (found 0 results, but was looking for 1)"
|
69
|
+
assert_equal(with_quoted_identifiers(expected), error.message)
|
82
70
|
end
|
83
71
|
|
84
72
|
def test_find_last_suburb
|
data/test/test_predicates.rb
CHANGED
@@ -16,10 +16,10 @@ class TestEqual < ActiveSupport::TestCase
|
|
16
16
|
|
17
17
|
connection = ActiveRecord::Base.connection
|
18
18
|
quoted = "#{connection.quote_table_name('departments')}.#{connection.quote_column_name('id')}"
|
19
|
-
expected = "(
|
19
|
+
expected = "(#{quoted} = 0 OR #{quoted} = 1 OR #{quoted} = 2)"
|
20
20
|
|
21
21
|
pred = cpk_or_predicate(predicates)
|
22
|
-
assert_equal(with_quoted_identifiers(expected), pred.
|
22
|
+
assert_equal(with_quoted_identifiers(expected), pred.to_sql)
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_and
|
data/test/test_santiago.rb
CHANGED
@@ -6,7 +6,7 @@ class TestSantiago < ActiveSupport::TestCase
|
|
6
6
|
fixtures :suburbs, :streets, :users, :articles, :readings
|
7
7
|
|
8
8
|
def test_normal_and_composite_associations
|
9
|
-
assert_not_nil @suburb = Suburb.find(1,1)
|
9
|
+
assert_not_nil @suburb = Suburb.find([1, 1])
|
10
10
|
assert_equal 1, @suburb.streets.length
|
11
11
|
|
12
12
|
assert_not_nil @street = Street.find(1)
|
data/test/test_serialize.rb
CHANGED
data/test/test_suite.rb
CHANGED
@@ -4,19 +4,19 @@ class TestTutorialExample < ActiveSupport::TestCase
|
|
4
4
|
fixtures :users, :groups, :memberships, :membership_statuses
|
5
5
|
|
6
6
|
def test_membership
|
7
|
-
assert(membership = Membership.find(1,1), "Cannot find a membership")
|
7
|
+
assert(membership = Membership.find([1, 1]), "Cannot find a membership")
|
8
8
|
assert(membership.user)
|
9
9
|
assert(membership.group)
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_status
|
13
|
-
assert(membership = Membership.find(1,1), "Cannot find a membership")
|
13
|
+
assert(membership = Membership.find([1, 1]), "Cannot find a membership")
|
14
14
|
assert(statuses = membership.statuses, "No has_many association to status")
|
15
15
|
assert_equal(membership, statuses.first.membership)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_count
|
19
|
-
assert(membership = Membership.find(1,1), "Cannot find a membership")
|
19
|
+
assert(membership = Membership.find([1, 1]), "Cannot find a membership")
|
20
20
|
assert_equal(1, membership.statuses.count)
|
21
21
|
end
|
22
22
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Dr Nic Williams
|
8
7
|
- Charlie Savage
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
@@ -17,28 +16,14 @@ dependencies:
|
|
17
16
|
requirements:
|
18
17
|
- - "~>"
|
19
18
|
- !ruby/object:Gem::Version
|
20
|
-
version: 4.0
|
19
|
+
version: 4.1.0
|
21
20
|
type: :runtime
|
22
21
|
prerelease: false
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
24
|
- - "~>"
|
26
25
|
- !ruby/object:Gem::Version
|
27
|
-
version: 4.0
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: mocha
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 1.1.0
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: 1.1.0
|
26
|
+
version: 4.1.0
|
42
27
|
description: Composite key support for ActiveRecord
|
43
28
|
email:
|
44
29
|
executables: []
|
@@ -52,11 +37,13 @@ files:
|
|
52
37
|
- init.rb
|
53
38
|
- install.rb
|
54
39
|
- lib/composite_primary_keys.rb
|
40
|
+
- lib/composite_primary_keys/active_model/dirty.rb
|
55
41
|
- lib/composite_primary_keys/active_record_overides.rb
|
56
42
|
- lib/composite_primary_keys/associations/association.rb
|
57
43
|
- lib/composite_primary_keys/associations/association_scope.rb
|
58
44
|
- lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb
|
59
45
|
- lib/composite_primary_keys/associations/has_many_association.rb
|
46
|
+
- lib/composite_primary_keys/associations/has_many_through_association.rb
|
60
47
|
- lib/composite_primary_keys/associations/join_dependency.rb
|
61
48
|
- lib/composite_primary_keys/associations/join_dependency/join_association.rb
|
62
49
|
- lib/composite_primary_keys/associations/join_dependency/join_part.rb
|
@@ -64,20 +51,18 @@ files:
|
|
64
51
|
- lib/composite_primary_keys/associations/preloader/belongs_to.rb
|
65
52
|
- lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb
|
66
53
|
- lib/composite_primary_keys/attribute_methods/dirty.rb
|
67
|
-
- lib/composite_primary_keys/attribute_methods/primary_key.rb
|
68
54
|
- lib/composite_primary_keys/attribute_methods/read.rb
|
69
55
|
- lib/composite_primary_keys/attribute_methods/write.rb
|
70
56
|
- lib/composite_primary_keys/base.rb
|
71
57
|
- lib/composite_primary_keys/composite_arrays.rb
|
72
58
|
- lib/composite_primary_keys/composite_predicates.rb
|
73
|
-
- lib/composite_primary_keys/composite_relation.rb
|
74
59
|
- lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb
|
75
60
|
- lib/composite_primary_keys/connection_adapters/abstract_adapter.rb
|
76
61
|
- lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
|
77
62
|
- lib/composite_primary_keys/core.rb
|
78
63
|
- lib/composite_primary_keys/dirty.rb
|
79
64
|
- lib/composite_primary_keys/fixtures.rb
|
80
|
-
- lib/composite_primary_keys/
|
65
|
+
- lib/composite_primary_keys/model_schema.rb
|
81
66
|
- lib/composite_primary_keys/nested_attributes.rb
|
82
67
|
- lib/composite_primary_keys/persistence.rb
|
83
68
|
- lib/composite_primary_keys/relation.rb
|
@@ -140,8 +125,6 @@ files:
|
|
140
125
|
- test/fixtures/membership_status.rb
|
141
126
|
- test/fixtures/membership_statuses.yml
|
142
127
|
- test/fixtures/memberships.yml
|
143
|
-
- test/fixtures/model_with_callback.rb
|
144
|
-
- test/fixtures/model_with_callbacks.yml
|
145
128
|
- test/fixtures/product.rb
|
146
129
|
- test/fixtures/product_tariff.rb
|
147
130
|
- test/fixtures/product_tariffs.yml
|
@@ -185,12 +168,10 @@ files:
|
|
185
168
|
- test/test_attribute_methods.rb
|
186
169
|
- test/test_attributes.rb
|
187
170
|
- test/test_calculations.rb
|
188
|
-
- test/test_callbacks.rb
|
189
171
|
- test/test_composite_arrays.rb
|
190
172
|
- test/test_counter_cache.rb
|
191
173
|
- test/test_create.rb
|
192
174
|
- test/test_delete.rb
|
193
|
-
- test/test_dumpable.rb
|
194
175
|
- test/test_dup.rb
|
195
176
|
- test/test_equal.rb
|
196
177
|
- test/test_exists.rb
|
@@ -199,7 +180,6 @@ files:
|
|
199
180
|
- test/test_ids.rb
|
200
181
|
- test/test_miscellaneous.rb
|
201
182
|
- test/test_nested_attributes.rb
|
202
|
-
- test/test_optimistic.rb
|
203
183
|
- test/test_pagination.rb
|
204
184
|
- test/test_polymorphic.rb
|
205
185
|
- test/test_predicates.rb
|
@@ -210,7 +190,7 @@ files:
|
|
210
190
|
- test/test_tutorial_example.rb
|
211
191
|
- test/test_update.rb
|
212
192
|
- test/test_validations.rb
|
213
|
-
homepage: https://github.com/
|
193
|
+
homepage: https://github.com/composite-primary-keys/composite_primary_keys
|
214
194
|
licenses: []
|
215
195
|
metadata: {}
|
216
196
|
post_install_message:
|
@@ -229,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
209
|
version: '0'
|
230
210
|
requirements: []
|
231
211
|
rubyforge_project: compositekeys
|
232
|
-
rubygems_version: 2.
|
212
|
+
rubygems_version: 2.2.2
|
233
213
|
signing_key:
|
234
214
|
specification_version: 4
|
235
215
|
summary: Composite key support for ActiveRecord
|
@@ -243,12 +223,10 @@ test_files:
|
|
243
223
|
- test/test_attributes.rb
|
244
224
|
- test/test_attribute_methods.rb
|
245
225
|
- test/test_calculations.rb
|
246
|
-
- test/test_callbacks.rb
|
247
226
|
- test/test_composite_arrays.rb
|
248
227
|
- test/test_counter_cache.rb
|
249
228
|
- test/test_create.rb
|
250
229
|
- test/test_delete.rb
|
251
|
-
- test/test_dumpable.rb
|
252
230
|
- test/test_dup.rb
|
253
231
|
- test/test_equal.rb
|
254
232
|
- test/test_exists.rb
|
@@ -257,7 +235,6 @@ test_files:
|
|
257
235
|
- test/test_ids.rb
|
258
236
|
- test/test_miscellaneous.rb
|
259
237
|
- test/test_nested_attributes.rb
|
260
|
-
- test/test_optimistic.rb
|
261
238
|
- test/test_pagination.rb
|
262
239
|
- test/test_polymorphic.rb
|
263
240
|
- test/test_predicates.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module AttributeMethods
|
3
|
-
module PrimaryKey
|
4
|
-
def id_was
|
5
|
-
sync_with_transaction_state
|
6
|
-
|
7
|
-
if self.composite?
|
8
|
-
self.class.primary_keys.map do |key_attr|
|
9
|
-
attribute_changed?(key_attr) ? changed_attributes[key_attr] : self.ids_hash[key_attr]
|
10
|
-
end
|
11
|
-
else
|
12
|
-
attribute_was(self.class.primary_key)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module CompositePrimaryKeys
|
2
|
-
module CompositeRelation
|
3
|
-
include CompositePrimaryKeys::ActiveRecord::Batches
|
4
|
-
include CompositePrimaryKeys::ActiveRecord::Calculations
|
5
|
-
include CompositePrimaryKeys::ActiveRecord::FinderMethods
|
6
|
-
include CompositePrimaryKeys::ActiveRecord::QueryMethods
|
7
|
-
|
8
|
-
def delete(id_or_array)
|
9
|
-
# Without CPK:
|
10
|
-
# where(primary_key => id_or_array).delete_all
|
11
|
-
|
12
|
-
id_or_array = if id_or_array.kind_of?(CompositePrimaryKeys::CompositeKeys)
|
13
|
-
[id_or_array]
|
14
|
-
else
|
15
|
-
Array(id_or_array)
|
16
|
-
end
|
17
|
-
|
18
|
-
id_or_array.each do |id|
|
19
|
-
where(cpk_id_predicate(table, self.primary_key, id)).delete_all
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def destroy(id_or_array)
|
24
|
-
# Without CPK:
|
25
|
-
#if id.is_a?(Array)
|
26
|
-
# id.map { |one_id| destroy(one_id) }
|
27
|
-
#else
|
28
|
-
# find(id).destroy
|
29
|
-
#end
|
30
|
-
|
31
|
-
id_or_array = if id_or_array.kind_of?(CompositePrimaryKeys::CompositeKeys)
|
32
|
-
[id_or_array]
|
33
|
-
else
|
34
|
-
Array(id_or_array)
|
35
|
-
end
|
36
|
-
|
37
|
-
id_or_array.each do |id|
|
38
|
-
where(cpk_id_predicate(table, self.primary_key, id)).each do |record|
|
39
|
-
record.destroy
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|