composite_primary_keys 7.0.5 → 7.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +4 -0
- data/lib/composite_primary_keys/base.rb +0 -2
- data/lib/composite_primary_keys/persistence.rb +39 -41
- data/lib/composite_primary_keys/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ac56003035ab69fb85bb4d3ec40644e5d3d80eb
|
4
|
+
data.tar.gz: 5fa4ebe741e44a8334b63a52ee050acdfa42140f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56e41e34385f9ae35be4a3c4fdeb8d5db149fdb6139122e67f169420637365c7c38d1e33e8e177eca175653fa0aa18fcd2d4e746126dafc66b6d20518b8c17d7
|
7
|
+
data.tar.gz: b84fc59f176103f616bd31fc202a6e12e2c611cf75957ee6e4304da3850103b55da205d04b89f809d2652f8ad8c851186d41369c742a58f8a8b0319c98187be7
|
data/History.rdoc
CHANGED
@@ -1,20 +1,8 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#pk = self.class.primary_key
|
7
|
-
#column = self.class.columns_hash[pk]
|
8
|
-
#substitute = self.class.connection.substitute_at(column, 0)
|
9
|
-
#relation = self.class.unscoped.where(
|
10
|
-
# self.class.arel_table[pk].eq(substitute))
|
11
|
-
#relation.bind_values = [[column, id]]
|
12
|
-
|
13
|
-
# run AR's original relation_for_destroy when primary key is not composite
|
14
|
-
if Array(self.class.primary_key).size <= 1
|
15
|
-
return super
|
16
|
-
end
|
17
|
-
|
1
|
+
module ActiveRecord
|
2
|
+
module Persistence
|
3
|
+
def relation_for_destroy
|
4
|
+
# CPK
|
5
|
+
if self.composite?
|
18
6
|
relation = self.class.unscoped
|
19
7
|
|
20
8
|
Array(self.class.primary_key).each_with_index do |key, index|
|
@@ -24,40 +12,50 @@ module CompositePrimaryKeys
|
|
24
12
|
relation.bind_values += [[column, self[key]]]
|
25
13
|
end
|
26
14
|
|
15
|
+
relation
|
16
|
+
else
|
17
|
+
pk = self.class.primary_key
|
18
|
+
column = self.class.columns_hash[pk]
|
19
|
+
substitute = self.class.connection.substitute_at(column, 0)
|
20
|
+
|
21
|
+
relation = self.class.unscoped.where(
|
22
|
+
self.class.arel_table[pk].eq(substitute))
|
23
|
+
|
24
|
+
relation.bind_values = [[column, id]]
|
27
25
|
relation
|
28
26
|
end
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
def touch(name = nil)
|
30
|
+
raise ActiveRecordError, "cannot touch on a new record object" unless persisted?
|
32
31
|
|
33
|
-
|
34
|
-
|
32
|
+
attributes = timestamp_attributes_for_update_in_model
|
33
|
+
attributes << name if name
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
unless attributes.empty?
|
36
|
+
current_time = current_time_from_proper_timezone
|
37
|
+
changes = {}
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
attributes.each do |column|
|
40
|
+
column = column.to_s
|
41
|
+
changes[column] = write_attribute(column, current_time)
|
42
|
+
end
|
44
43
|
|
45
|
-
|
44
|
+
changes[self.class.locking_column] = increment_lock if locking_enabled?
|
46
45
|
|
47
|
-
|
46
|
+
changed_attributes.except!(*changes.keys)
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
relation = self.class.send(:relation)
|
49
|
+
arel_table = self.class.arel_table
|
50
|
+
primary_key = self.class.primary_key
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
52
|
+
# CPK
|
53
|
+
#self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1
|
54
|
+
primary_key_predicate = relation.cpk_id_predicate(arel_table, Array(primary_key), Array(id))
|
55
|
+
self.class.unscoped.where(primary_key_predicate).update_all(changes) == 1
|
56
|
+
else
|
57
|
+
true
|
60
58
|
end
|
61
59
|
end
|
62
60
|
end
|
63
|
-
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.0.
|
4
|
+
version: 7.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|