composite_primary_keys 12.0.0.rc2 → 12.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/composite_primary_keys/relation.rb +10 -11
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/test_delete.rb +2 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f64b2e651fc3f4697d277ef8f65415cd2322b9c8e2e08a962ff5c7a7e2558bc0
|
4
|
+
data.tar.gz: '059a2e133e9b33caa48f8527c8504a9e79e6aedd038b4b7bbdc07a4fe07f846c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f30eac243862e7c531278c969384efe3ebfecb94c79085c8deace569ba7828e08efa71b27c7c72114fa3c81bf96a869c1f1ec7865afd72cf43b78e6aef16ac2
|
7
|
+
data.tar.gz: ee7923da55d493bba06bbbd401ebdbb52d66d41d289f795e3b1fd1592fee4d93d17b553b3f9ff4c26f2510dd5cfd867134d5745a77bd72c24bec23f9af0cdefa
|
@@ -25,7 +25,7 @@ module ActiveRecord
|
|
25
25
|
end
|
26
26
|
|
27
27
|
stmt = Arel::UpdateManager.new
|
28
|
-
|
28
|
+
# CPK
|
29
29
|
if @klass.composite?
|
30
30
|
stmt.table(table)
|
31
31
|
subselect = arel.clone
|
@@ -60,10 +60,8 @@ module ActiveRecord
|
|
60
60
|
|
61
61
|
def delete_all
|
62
62
|
invalid_methods = INVALID_METHODS_FOR_DELETE_ALL.select do |method|
|
63
|
-
|
64
|
-
|
65
|
-
SINGLE_VALUE_METHODS.include?(method) ? value : value.any?
|
66
|
-
end
|
63
|
+
value = @values[method]
|
64
|
+
method == :distinct ? value : value&.any?
|
67
65
|
end
|
68
66
|
if invalid_methods.any?
|
69
67
|
raise ActiveRecordError.new("delete_all doesn't support #{invalid_methods.join(', ')}")
|
@@ -75,22 +73,23 @@ module ActiveRecord
|
|
75
73
|
end
|
76
74
|
|
77
75
|
stmt = Arel::DeleteManager.new
|
76
|
+
# CPK
|
78
77
|
if @klass.composite?
|
79
|
-
|
78
|
+
stmt.from(table)
|
79
|
+
subselect = arel.clone
|
80
|
+
arel_attributes = primary_keys.map do |key|
|
80
81
|
arel_attribute(key)
|
81
82
|
end.to_composite_keys
|
82
|
-
subselect =
|
83
|
-
|
84
|
-
stmt.from(table)
|
85
|
-
stmt.key = arel_attributes.in(subselect)
|
83
|
+
subselect.projections = arel_attributes
|
84
|
+
stmt.wheres = [arel_attributes.in(subselect)]
|
86
85
|
else
|
87
86
|
stmt.from(arel.join_sources.empty? ? table : arel.source)
|
88
87
|
stmt.key = arel_attribute(primary_key)
|
88
|
+
stmt.wheres = arel.constraints
|
89
89
|
end
|
90
90
|
stmt.take(arel.limit)
|
91
91
|
stmt.offset(arel.offset)
|
92
92
|
stmt.order(*arel.orders)
|
93
|
-
stmt.wheres = arel.constraints
|
94
93
|
|
95
94
|
affected = @klass.connection.delete(stmt, "#{@klass} Destroy")
|
96
95
|
|
data/test/test_delete.rb
CHANGED
@@ -29,13 +29,12 @@ class TestDelete < ActiveSupport::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_delete_all_with_join
|
32
|
-
|
32
|
+
employee = employees(:mindy)
|
33
33
|
|
34
34
|
assert_equal(4, Department.count)
|
35
35
|
|
36
36
|
Department.joins(:employees).
|
37
|
-
where('
|
38
|
-
where('departments.location_id = ?', department.location_id).
|
37
|
+
where('employees.name = ?', employee.name).
|
39
38
|
delete_all
|
40
39
|
|
41
40
|
assert_equal(3, Department.count)
|