active_record-json_associations 0.12.0 → 0.13.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 +4 -4
- data/.github/workflows/ci.yml +2 -11
- data/Appraisals +5 -4
- data/README.md +1 -1
- data/gemfiles/rails_7.0.gemfile +1 -0
- data/gemfiles/{rails_6.1.gemfile → rails_7.2.gemfile} +1 -1
- data/lib/active_record/json_associations/version.rb +1 -1
- data/lib/active_record/json_associations.rb +17 -8
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c6e92de811720d3a6f9ed242d374f6f4b6e604e09977476f619355918c22b6ea
|
|
4
|
+
data.tar.gz: 31e0f02c6b52dbc6994d3d4c2ae7016287a2d2488ad1371ddac6ba65bf9598d8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1773bd6dd9c36865e772b81c6e0c7ac9ece43028cdc1c5e254047dcc5349bb0cc4a8073b30de3cd114bed20be88ab30495b6f5b2f9a241caa78f9fd8c1a67908
|
|
7
|
+
data.tar.gz: 4312ec59acc30da426d32c53dea432bcdd2064a21fea69faa826f6dd1347887668e6fc7280be9a107973ad9ac6f19745e43df382c573831b71623ed3f8889a32
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -5,17 +5,8 @@ jobs:
|
|
|
5
5
|
strategy:
|
|
6
6
|
fail-fast: false
|
|
7
7
|
matrix:
|
|
8
|
-
gemfile: [
|
|
9
|
-
ruby: [
|
|
10
|
-
exclude:
|
|
11
|
-
- gemfile: rails_5.1
|
|
12
|
-
ruby: 3.0
|
|
13
|
-
- gemfile: rails_5.2
|
|
14
|
-
ruby: 3.0
|
|
15
|
-
- gemfile: rails_7.0
|
|
16
|
-
ruby: 2.6
|
|
17
|
-
- gemfile: rails_7.1
|
|
18
|
-
ruby: 2.6
|
|
8
|
+
gemfile: [ rails_7.0, rails_7.1, rails_7.2 ]
|
|
9
|
+
ruby: [ 3.1, 3.2, 3.3 ]
|
|
19
10
|
|
|
20
11
|
runs-on: ubuntu-latest
|
|
21
12
|
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
data/Appraisals
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
appraise "rails-6.1" do
|
|
2
|
-
gem "rails", "~>6.1.0"
|
|
3
|
-
end
|
|
4
|
-
|
|
5
1
|
appraise "rails-7.0" do
|
|
6
2
|
gem "rails", "~>7.0.0"
|
|
3
|
+
gem "sqlite3", "~>1.0"
|
|
7
4
|
end
|
|
8
5
|
|
|
9
6
|
appraise "rails-7.1" do
|
|
10
7
|
gem "rails", "~>7.1.0"
|
|
11
8
|
end
|
|
12
9
|
|
|
10
|
+
appraise "rails-7.2" do
|
|
11
|
+
gem "rails", "~>7.2.0"
|
|
12
|
+
end
|
|
13
|
+
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ActiveRecord::JsonAssociations
|
|
2
2
|
|
|
3
|
-
[](https://github.com/botandrose/active_record-json_associations/actions/workflows/ci.yml)
|
|
4
4
|
[](https://codeclimate.com/github/botandrose/active_record-json_associations)
|
|
5
5
|
|
|
6
6
|
Instead of keeping the foreign keys on the children, or in a many-to-many join table, let's keep them in a JSON array on the parent.
|
data/gemfiles/rails_7.0.gemfile
CHANGED
|
@@ -4,10 +4,16 @@ require "json"
|
|
|
4
4
|
module ActiveRecord
|
|
5
5
|
module JsonAssociations
|
|
6
6
|
FIELD_INCLUDE_SCOPE_BUILDER_PROC = proc do |context, field, id|
|
|
7
|
-
context.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
using_json = context.columns_hash[field.to_s].type == :json
|
|
8
|
+
|
|
9
|
+
if using_json
|
|
10
|
+
context.where("JSON_CONTAINS(#{field}, ?, '$')", id.to_json)
|
|
11
|
+
else
|
|
12
|
+
context.where("#{field}='[#{id}]'").or(
|
|
13
|
+
context.where("#{field} LIKE '[#{id},%'")).or(
|
|
14
|
+
context.where("#{field} LIKE '%,#{id},%'")).or(
|
|
15
|
+
context.where("#{field} LIKE '%,#{id}]'"))
|
|
16
|
+
end
|
|
11
17
|
end
|
|
12
18
|
private_constant :FIELD_INCLUDE_SCOPE_BUILDER_PROC
|
|
13
19
|
|
|
@@ -20,11 +26,14 @@ module ActiveRecord
|
|
|
20
26
|
|
|
21
27
|
class_name ||= one.classify
|
|
22
28
|
|
|
29
|
+
using_json = columns_hash[one_ids.to_s].type == :json
|
|
23
30
|
|
|
24
|
-
if
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
if !using_json
|
|
32
|
+
if ActiveRecord.version >= Gem::Version.new("7.1")
|
|
33
|
+
serialize one_ids, coder: JSON
|
|
34
|
+
else
|
|
35
|
+
serialize one_ids, JSON
|
|
36
|
+
end
|
|
28
37
|
end
|
|
29
38
|
|
|
30
39
|
if touch
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_record-json_associations
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Micah Geisel
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-01-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -140,9 +140,9 @@ files:
|
|
|
140
140
|
- Rakefile
|
|
141
141
|
- active_record-json_associations.gemspec
|
|
142
142
|
- bin/setup
|
|
143
|
-
- gemfiles/rails_6.1.gemfile
|
|
144
143
|
- gemfiles/rails_7.0.gemfile
|
|
145
144
|
- gemfiles/rails_7.1.gemfile
|
|
145
|
+
- gemfiles/rails_7.2.gemfile
|
|
146
146
|
- lib/active_record/json_associations.rb
|
|
147
147
|
- lib/active_record/json_associations/version.rb
|
|
148
148
|
- spec/json_associations_spec.rb
|
|
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
166
166
|
- !ruby/object:Gem::Version
|
|
167
167
|
version: '0'
|
|
168
168
|
requirements: []
|
|
169
|
-
rubygems_version: 3.
|
|
169
|
+
rubygems_version: 3.5.11
|
|
170
170
|
signing_key:
|
|
171
171
|
specification_version: 4
|
|
172
172
|
summary: Instead of a many-to-many join table, serialize the ids into a JSON array.
|