active_record-json_associations 0.11.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: 74ef04233cdf6b923c6be5762d8aa373428bf0ddd74a8fe48f46cbd9b3f16851
4
- data.tar.gz: b40d4491c6619ecd3d858864706e3e05e459a3d3f3b20f50eadf0eed416c05db
3
+ metadata.gz: c6e92de811720d3a6f9ed242d374f6f4b6e604e09977476f619355918c22b6ea
4
+ data.tar.gz: 31e0f02c6b52dbc6994d3d4c2ae7016287a2d2488ad1371ddac6ba65bf9598d8
5
5
  SHA512:
6
- metadata.gz: ea1b394dbe6ba8524b50228d9f226af19699171105cd8dda69b7f92f1b1fee6a9dfa06aa85301bfc2403fdb3831972799a38d01a6353c035235e1935fcc57bc2
7
- data.tar.gz: e37aec9fff5cfe740cda139ed46c1b7fada912a30a26ebed3945ac6e0a8c7e9356071360278323867f949a666654cf47c9d351b2431c5a2b75fc568273b5439d
6
+ metadata.gz: 1773bd6dd9c36865e772b81c6e0c7ac9ece43028cdc1c5e254047dcc5349bb0cc4a8073b30de3cd114bed20be88ab30495b6f5b2f9a241caa78f9fd8c1a67908
7
+ data.tar.gz: 4312ec59acc30da426d32c53dea432bcdd2064a21fea69faa826f6dd1347887668e6fc7280be9a107973ad9ac6f19745e43df382c573831b71623ed3f8889a32
@@ -5,15 +5,8 @@ jobs:
5
5
  strategy:
6
6
  fail-fast: false
7
7
  matrix:
8
- gemfile: [ rails_5.1, rails_5.2, rails_6.0, rails_6.1, rails_7.0 ]
9
- ruby: [ 2.6, 2.7, '3.0' ]
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
8
+ gemfile: [ rails_7.0, rails_7.1, rails_7.2 ]
9
+ ruby: [ 3.1, 3.2, 3.3 ]
17
10
 
18
11
  runs-on: ubuntu-latest
19
12
  env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
data/Appraisals CHANGED
@@ -1,20 +1,13 @@
1
- appraise "rails-5.1" do
2
- gem "rails", "~>5.1.0"
3
- end
4
-
5
- appraise "rails-5.2" do
6
- gem "rails", "~>5.2.0"
7
- end
8
-
9
- appraise "rails-6.0" do
10
- gem "rails", "~>6.0.0"
1
+ appraise "rails-7.0" do
2
+ gem "rails", "~>7.0.0"
3
+ gem "sqlite3", "~>1.0"
11
4
  end
12
5
 
13
- appraise "rails-6.1" do
14
- gem "rails", "~>6.1.0"
6
+ appraise "rails-7.1" do
7
+ gem "rails", "~>7.1.0"
15
8
  end
16
9
 
17
- appraise "rails-7.0" do
18
- gem "rails", "~>7.0.0"
10
+ appraise "rails-7.2" do
11
+ gem "rails", "~>7.2.0"
19
12
  end
20
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", "~>5.1.0"
5
+ gem "rails", "~>7.1.0"
6
6
 
7
7
  gemspec path: "../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~>5.2.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.11.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,7 +26,15 @@ module ActiveRecord
20
26
 
21
27
  class_name ||= one.classify
22
28
 
23
- serialize one_ids, JSON
29
+ using_json = columns_hash[one_ids.to_s].type == :json
30
+
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
37
+ end
24
38
 
25
39
  if touch
26
40
  after_commit do
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.11.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: 2022-01-25 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,11 +140,9 @@ files:
140
140
  - Rakefile
141
141
  - active_record-json_associations.gemspec
142
142
  - bin/setup
143
- - gemfiles/rails_5.1.gemfile
144
- - gemfiles/rails_5.2.gemfile
145
- - gemfiles/rails_6.0.gemfile
146
- - gemfiles/rails_6.1.gemfile
147
143
  - gemfiles/rails_7.0.gemfile
144
+ - gemfiles/rails_7.1.gemfile
145
+ - gemfiles/rails_7.2.gemfile
148
146
  - lib/active_record/json_associations.rb
149
147
  - lib/active_record/json_associations/version.rb
150
148
  - spec/json_associations_spec.rb
@@ -168,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
166
  - !ruby/object:Gem::Version
169
167
  version: '0'
170
168
  requirements: []
171
- rubygems_version: 3.1.6
169
+ rubygems_version: 3.5.11
172
170
  signing_key:
173
171
  specification_version: 4
174
172
  summary: Instead of a many-to-many join table, serialize the ids into a JSON array.
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~>6.0.0"
6
-
7
- gemspec path: "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~>6.1.0"
6
-
7
- gemspec path: "../"