activerecord-jsonb-associations 0.1.0 → 0.2.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 +5 -5
- data/README.md +2 -0
- data/lib/activerecord/jsonb/associations/association_scope.rb +2 -1
- data/lib/activerecord/jsonb/associations/builder/belongs_to.rb +19 -0
- data/lib/activerecord/jsonb/associations/join_dependency/join_association.rb +6 -1
- data/lib/activerecord/jsonb/associations/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6dda2c511ebc60b30aa81c8cea90f006e42b5d3105052f6604c417af3e919c69
|
4
|
+
data.tar.gz: 02d8a8f20e4cc088d782449a65e08f2cee828d871fae75e220e110d1d4ef6d5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 692303b45595a928a36cdb6d192786955c0b232006fa18fc349051e2ac81bd613e223068ed67b60f3e3752a1f2a797899a9fc99118dd60bb089f34d54b80bb82
|
7
|
+
data.tar.gz: a978d95bcb59ae742df403a0967774fcf412c5df09a751ffa80c5aede9a79950efcf87493fb5a739b08e241e4d9198a396960c7c048b884785b3bfe1883e1865
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# activerecord-json-associations
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/activerecord-jsonb-associations)
|
4
|
+
|
3
5
|
Use PostgreSQL JSONB fields to store association information of your models.
|
4
6
|
|
5
7
|
This gem was created as a solution to this [task](http://cultofmartians.com/tasks/active-record-jsonb-associations.html) from [EvilMartians](http://evilmartians.com).
|
@@ -9,7 +9,7 @@ module ActiveRecord
|
|
9
9
|
|
10
10
|
join_keys = reflection.join_keys
|
11
11
|
key = join_keys.key
|
12
|
-
value = transform_value(owner[
|
12
|
+
value = transform_value(owner[join_keys.foreign_key])
|
13
13
|
|
14
14
|
if reflection.options.key?(:foreign_store)
|
15
15
|
apply_jsonb_scope(
|
@@ -18,6 +18,7 @@ module ActiveRecord
|
|
18
18
|
key, value
|
19
19
|
)
|
20
20
|
elsif reflection && reflection.options.key?(:store)
|
21
|
+
return super if reflection.belongs_to?
|
21
22
|
pluralized_key = key.pluralize
|
22
23
|
|
23
24
|
apply_jsonb_scope(
|
@@ -35,6 +35,15 @@ module ActiveRecord
|
|
35
35
|
#{reflection.options[:store]}['#{foreign_key}']
|
36
36
|
end
|
37
37
|
|
38
|
+
def _read_attribute(attr_name)
|
39
|
+
key = attr_name.to_s
|
40
|
+
if key.ends_with?('_id') && #{reflection.options[:store]}.keys.include?(key)
|
41
|
+
#{reflection.options[:store]}[key]
|
42
|
+
else
|
43
|
+
super
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
38
47
|
def [](key)
|
39
48
|
key = key.to_s
|
40
49
|
if key.ends_with?('_id') &&
|
@@ -44,6 +53,16 @@ module ActiveRecord
|
|
44
53
|
super
|
45
54
|
end
|
46
55
|
end
|
56
|
+
|
57
|
+
def []=(key, value)
|
58
|
+
key = key.to_s
|
59
|
+
if key.ends_with?('_id') &&
|
60
|
+
#{reflection.options[:store]}.keys.include?(key)
|
61
|
+
#{reflection.options[:store]}[key] = value
|
62
|
+
else
|
63
|
+
super
|
64
|
+
end
|
65
|
+
end
|
47
66
|
CODE
|
48
67
|
end
|
49
68
|
end
|
@@ -10,7 +10,12 @@ module ActiveRecord
|
|
10
10
|
table, table[reflection.options[:foreign_store]],
|
11
11
|
key, foreign_table, foreign_key
|
12
12
|
)
|
13
|
-
elsif reflection.options.key?(:store)
|
13
|
+
elsif reflection.options.key?(:store) && reflection.belongs_to?
|
14
|
+
build_eq_constraint(
|
15
|
+
foreign_table, foreign_table[reflection.options[:store]],
|
16
|
+
foreign_key, table, key
|
17
|
+
)
|
18
|
+
elsif reflection.options.key?(:store) # && reflection.has_one?
|
14
19
|
build_contains_constraint(
|
15
20
|
table, table[reflection.options[:store]],
|
16
21
|
key.pluralize, foreign_table, foreign_key
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-jsonb-associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Lebedev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.6
|
92
|
+
rubygems_version: 2.7.6
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: Gem for storing association information using PostgreSQL JSONB columns
|