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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6216fb9d4e62c9c8cb923d201468dcf3cf6843b287e747a068fd646e9c49a3f
4
- data.tar.gz: 31f562eb9e8e9f2d029a59539977bb2e10a21555532b1dc3031a971487335f69
3
+ metadata.gz: c6e92de811720d3a6f9ed242d374f6f4b6e604e09977476f619355918c22b6ea
4
+ data.tar.gz: 31e0f02c6b52dbc6994d3d4c2ae7016287a2d2488ad1371ddac6ba65bf9598d8
5
5
  SHA512:
6
- metadata.gz: c3913f45325fbd16a2983f9ec5e9d38d9f4121984d585baacb782a40ad01b54c99de287eeca8151b2aa1556153aee3157d8776c9f0515688e5122ffd7f0b61a5
7
- data.tar.gz: 7a280e3431ed93c53719ced45e48dc85f39c797ffd2e39483a8bb060a3f18d63c3f1c99ff3c33a5b55e1f1c74fe0721b5786fa2b28853aefb035dbf91e3e40dc
6
+ metadata.gz: 1773bd6dd9c36865e772b81c6e0c7ac9ece43028cdc1c5e254047dcc5349bb0cc4a8073b30de3cd114bed20be88ab30495b6f5b2f9a241caa78f9fd8c1a67908
7
+ data.tar.gz: 4312ec59acc30da426d32c53dea432bcdd2064a21fea69faa826f6dd1347887668e6fc7280be9a107973ad9ac6f19745e43df382c573831b71623ed3f8889a32
@@ -5,17 +5,8 @@ jobs:
5
5
  strategy:
6
6
  fail-fast: false
7
7
  matrix:
8
- gemfile: [ rails_6.1, rails_7.0, rails_7.1 ]
9
- ruby: [ 2.6, 2.7, '3.0', 3.1, 3.2 ]
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
- [![Build Status](https://travis-ci.org/botandrose/active_record-json_associations.svg)](https://travis-ci.org/botandrose/active_record-json_associations)
3
+ [![CI Status](https://github.com/botandrose/active_record-json_associations/actions/workflows/ci.yml/badge.svg)](https://github.com/botandrose/active_record-json_associations/actions/workflows/ci.yml)
4
4
  [![Code Climate](https://codeclimate.com/github/botandrose/active_record-json_associations/badges/gpa.svg)](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.
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~>7.0.0"
6
+ gem "sqlite3", "~>1.0"
6
7
 
7
8
  gemspec path: "../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~>6.1.0"
5
+ gem "rails", "~>7.2.0"
6
6
 
7
7
  gemspec path: "../"
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module JsonAssociations
3
- VERSION = "0.12.0"
3
+ VERSION = "0.13.0"
4
4
  end
5
5
  end
@@ -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.where("#{field}='[#{id}]'").or(
8
- context.where("#{field} LIKE '[#{id},%'")).or(
9
- context.where("#{field} LIKE '%,#{id},%'")).or(
10
- context.where("#{field} LIKE '%,#{id}]'"))
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 ActiveRecord.version >= Gem::Version.new("7.1")
25
- serialize one_ids, coder: JSON
26
- else
27
- serialize one_ids, JSON
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.12.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: 2023-11-14 00:00:00.000000000 Z
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.2.32
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.