torque-postgresql 1.1.6 → 1.1.7
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/lib/torque/postgresql/associations/belongs_to_many_association.rb +14 -10
- data/lib/torque/postgresql/associations/preloader.rb +9 -1
- data/lib/torque/postgresql/autosave_association.rb +4 -4
- data/lib/torque/postgresql/config.rb +2 -0
- data/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb +38 -4
- data/lib/torque/postgresql/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ac2d4e3c96cf93edeac515986a6b7ba3ca412712c6eb19a38f09e0b0e5e448a
|
4
|
+
data.tar.gz: 133b756202e8e39738d7bda361f3fd9544829ef817b7ac518f972bf175da93c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08a2cb8062f7bdcf6497f4c2b33dc102c6df5d45ed5c82f6c772caeddb02f7a87056b06b13e6c09359b9db52dff46eabcb64f644e17682b1f830fdd988ff44ea'
|
7
|
+
data.tar.gz: f419dd80f7a3c9972b0eb469ed63bf5454ede498ee688761f7c99587db8b2d48d06b5b40e4696a1760ea077f750d966a9e67a500b5b2d4b8b0fa3fccc1c0f884
|
@@ -28,11 +28,11 @@ module Torque
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def ids_reader
|
31
|
-
owner[
|
31
|
+
owner[source_attr]
|
32
32
|
end
|
33
33
|
|
34
34
|
def ids_writer(new_ids)
|
35
|
-
column =
|
35
|
+
column = source_attr
|
36
36
|
owner.update_column(column, owner[column] = new_ids.presence)
|
37
37
|
@association_scope = nil
|
38
38
|
end
|
@@ -40,8 +40,8 @@ module Torque
|
|
40
40
|
def insert_record(record, *)
|
41
41
|
super
|
42
42
|
|
43
|
-
attribute = (ids_reader || owner[
|
44
|
-
attribute.push(record[
|
43
|
+
attribute = (ids_reader || owner[source_attr] = [])
|
44
|
+
attribute.push(record[klass_attr])
|
45
45
|
record
|
46
46
|
end
|
47
47
|
|
@@ -50,8 +50,8 @@ module Torque
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def include?(record)
|
53
|
-
list = owner[
|
54
|
-
ids_reader && ids_reader.include?(record[
|
53
|
+
list = owner[source_attr]
|
54
|
+
ids_reader && ids_reader.include?(record[klass_attr])
|
55
55
|
end
|
56
56
|
|
57
57
|
private
|
@@ -65,7 +65,7 @@ module Torque
|
|
65
65
|
# When the idea is to nulligy the association, then just set the owner
|
66
66
|
# +primary_key+ as empty
|
67
67
|
def delete_count(method, scope, ids = nil)
|
68
|
-
ids ||= scope.pluck(
|
68
|
+
ids ||= scope.pluck(klass_attr)
|
69
69
|
scope.delete_all if method == :delete_all
|
70
70
|
remove_stash_records(ids)
|
71
71
|
end
|
@@ -76,13 +76,13 @@ module Torque
|
|
76
76
|
|
77
77
|
# Deletes the records according to the <tt>:dependent</tt> option.
|
78
78
|
def delete_records(records, method)
|
79
|
-
ids = Array.wrap(records).each_with_object(
|
79
|
+
ids = Array.wrap(records).each_with_object(klass_attr).map(&:[])
|
80
80
|
|
81
81
|
if method == :destroy
|
82
82
|
records.each(&:destroy!)
|
83
83
|
remove_stash_records(ids)
|
84
84
|
else
|
85
|
-
scope = self.scope.where(
|
85
|
+
scope = self.scope.where(klass_attr => records)
|
86
86
|
delete_count(method, scope, ids)
|
87
87
|
end
|
88
88
|
end
|
@@ -98,10 +98,14 @@ module Torque
|
|
98
98
|
ids_writer(ids_reader - Array.wrap(ids))
|
99
99
|
end
|
100
100
|
|
101
|
-
def
|
101
|
+
def source_attr
|
102
102
|
reflection.foreign_key
|
103
103
|
end
|
104
104
|
|
105
|
+
def klass_attr
|
106
|
+
reflection.active_record_primary_key
|
107
|
+
end
|
108
|
+
|
105
109
|
def difference(a, b)
|
106
110
|
a - b
|
107
111
|
end
|
@@ -5,7 +5,15 @@ unless Torque::PostgreSQL::AR521
|
|
5
5
|
module PostgreSQL
|
6
6
|
module Associations
|
7
7
|
module Preloader
|
8
|
-
BelongsToMany
|
8
|
+
class BelongsToMany < ::ActiveRecord::Associations::Preloader::HasMany
|
9
|
+
def association_key_name
|
10
|
+
reflection.active_record_primary_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def owner_key_name
|
14
|
+
reflection.foreign_key
|
15
|
+
end
|
16
|
+
end
|
9
17
|
|
10
18
|
def preloader_for(reflection, owners, *)
|
11
19
|
return AlreadyLoaded \
|
@@ -25,11 +25,11 @@ module Torque
|
|
25
25
|
association = association_instance_get(reflection.name)
|
26
26
|
return unless association
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
klass_attr = reflection.active_record_primary_key
|
29
|
+
source_attr = reflection.foreign_key
|
30
30
|
|
31
|
-
records = association.target.each_with_object(
|
32
|
-
write_attribute(
|
31
|
+
records = association.target.each_with_object(klass_attr)
|
32
|
+
write_attribute(source_attr, records.map(&:read_attribute).compact)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -3,6 +3,8 @@ module Torque
|
|
3
3
|
include ActiveSupport::Configurable
|
4
4
|
|
5
5
|
# Stores a version check for compatibility purposes
|
6
|
+
AR510 = (ActiveRecord.gem_version >= Gem::Version.new('5.1.0'))
|
7
|
+
AR520 = (ActiveRecord.gem_version >= Gem::Version.new('5.2.0'))
|
6
8
|
AR521 = (ActiveRecord.gem_version >= Gem::Version.new('5.2.1'))
|
7
9
|
AR523 = (ActiveRecord.gem_version >= Gem::Version.new('5.2.3'))
|
8
10
|
|
@@ -10,6 +10,10 @@ module Torque
|
|
10
10
|
true
|
11
11
|
end
|
12
12
|
|
13
|
+
def belongs_to?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
13
17
|
def collection?
|
14
18
|
true
|
15
19
|
end
|
@@ -19,7 +23,7 @@ module Torque
|
|
19
23
|
end
|
20
24
|
|
21
25
|
def foreign_key
|
22
|
-
@foreign_key ||= options[:
|
26
|
+
@foreign_key ||= options[:foreign_key] || derive_foreign_key.freeze
|
23
27
|
end
|
24
28
|
|
25
29
|
def association_foreign_key
|
@@ -27,16 +31,46 @@ module Torque
|
|
27
31
|
end
|
28
32
|
|
29
33
|
def active_record_primary_key
|
30
|
-
@active_record_primary_key ||= options[:
|
34
|
+
@active_record_primary_key ||= options[:primary_key] || derive_primary_key
|
35
|
+
end
|
36
|
+
|
37
|
+
unless PostgreSQL::AR510
|
38
|
+
def join_keys(*)
|
39
|
+
JoinKeys.new(join_pk, join_fk)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if PostgreSQL::AR520
|
44
|
+
def join_primary_key(*)
|
45
|
+
active_record_primary_key
|
46
|
+
end
|
47
|
+
|
48
|
+
def join_foreign_key
|
49
|
+
foreign_key
|
50
|
+
end
|
51
|
+
else
|
52
|
+
def join_id_for(owner)
|
53
|
+
owner[foreign_key]
|
54
|
+
end
|
31
55
|
end
|
32
56
|
|
33
57
|
private
|
34
58
|
|
35
|
-
|
36
|
-
|
59
|
+
unless PostgreSQL::AR520
|
60
|
+
def join_pk(*)
|
61
|
+
active_record_primary_key
|
62
|
+
end
|
63
|
+
|
64
|
+
def join_fk
|
65
|
+
foreign_key
|
66
|
+
end
|
37
67
|
end
|
38
68
|
|
39
69
|
def derive_primary_key
|
70
|
+
klass.primary_key
|
71
|
+
end
|
72
|
+
|
73
|
+
def derive_foreign_key
|
40
74
|
"#{name.to_s.singularize}_ids"
|
41
75
|
end
|
42
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torque-postgresql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|