composite_primary_keys 7.0.5 → 7.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b80c3c585051897678d097a60e5e2d2e0aaf9ec3
4
- data.tar.gz: c6b042d7c81d77f5e8e1712c9808574288ac672c
3
+ metadata.gz: 6ac56003035ab69fb85bb4d3ec40644e5d3d80eb
4
+ data.tar.gz: 5fa4ebe741e44a8334b63a52ee050acdfa42140f
5
5
  SHA512:
6
- metadata.gz: 1ccdf4ac7aed2c8c3856ecbcf238662f9c8e04e2a34e156542645be631e61d7d2b3299d106ee6d5c4afb911fea69bb5e7e551422e573dfcca59664854a3014a4
7
- data.tar.gz: 61238d4592fd9ba1b9f984c233399f6ccbbc4d2b6c6abd12ebedb174cc3094557043e5034941e3b3da192560bc17cb34857e70e959026a88a786f5208cf6755e
6
+ metadata.gz: 56e41e34385f9ae35be4a3c4fdeb8d5db149fdb6139122e67f169420637365c7c38d1e33e8e177eca175653fa0aa18fcd2d4e746126dafc66b6d20518b8c17d7
7
+ data.tar.gz: b84fc59f176103f616bd31fc202a6e12e2c611cf75957ee6e4304da3850103b55da205d04b89f809d2652f8ad8c851186d41369c742a58f8a8b0319c98187be7
@@ -1,3 +1,7 @@
1
+ == 7.0.6 (2014-07-22)
2
+
3
+ * Change the way we override ActiveRecord::Persistence to call sequence of included modules (such as callbacks)
4
+
1
5
  == 7.0.5 (2014-07-21)
2
6
 
3
7
  * Remove overriden Postgresql adapter code (Charlie Savage)
@@ -3,8 +3,6 @@ module ActiveRecord
3
3
  end
4
4
 
5
5
  class Base
6
- include CompositePrimaryKeys::ActiveRecord::Persistence
7
-
8
6
  INVALID_FOR_COMPOSITE_KEYS = 'Not appropriate for composite primary keys'
9
7
  NOT_IMPLEMENTED_YET = 'Not implemented for composite primary keys yet'
10
8
 
@@ -1,20 +1,8 @@
1
- module CompositePrimaryKeys
2
- module ActiveRecord
3
- module Persistence
4
- def relation_for_destroy
5
- # CPK
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
- def touch(name = nil)
31
- raise ActiveRecordError, "cannot touch on a new record object" unless persisted?
29
+ def touch(name = nil)
30
+ raise ActiveRecordError, "cannot touch on a new record object" unless persisted?
32
31
 
33
- attributes = timestamp_attributes_for_update_in_model
34
- attributes << name if name
32
+ attributes = timestamp_attributes_for_update_in_model
33
+ attributes << name if name
35
34
 
36
- unless attributes.empty?
37
- current_time = current_time_from_proper_timezone
38
- changes = {}
35
+ unless attributes.empty?
36
+ current_time = current_time_from_proper_timezone
37
+ changes = {}
39
38
 
40
- attributes.each do |column|
41
- column = column.to_s
42
- changes[column] = write_attribute(column, current_time)
43
- end
39
+ attributes.each do |column|
40
+ column = column.to_s
41
+ changes[column] = write_attribute(column, current_time)
42
+ end
44
43
 
45
- changes[self.class.locking_column] = increment_lock if locking_enabled?
44
+ changes[self.class.locking_column] = increment_lock if locking_enabled?
46
45
 
47
- changed_attributes.except!(*changes.keys)
46
+ changed_attributes.except!(*changes.keys)
48
47
 
49
- relation = self.class.send(:relation)
50
- arel_table = self.class.arel_table
51
- primary_key = self.class.primary_key
48
+ relation = self.class.send(:relation)
49
+ arel_table = self.class.arel_table
50
+ primary_key = self.class.primary_key
52
51
 
53
- # CPK
54
- #self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1
55
- primary_key_predicate = relation.cpk_id_predicate(arel_table, Array(primary_key), Array(id))
56
- self.class.unscoped.where(primary_key_predicate).update_all(changes) == 1
57
- else
58
- true
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
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 7
4
4
  MINOR = 0
5
- TINY = 5
5
+ TINY = 6
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  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.5
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-21 00:00:00.000000000 Z
11
+ date: 2014-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord