schema_associations 1.2.6 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/prs.yml +173 -0
  3. data/.gitignore +1 -0
  4. data/.simplecov +20 -0
  5. data/Gemfile +5 -0
  6. data/README.md +57 -16
  7. data/Rakefile +4 -13
  8. data/gemfiles/Gemfile.base +1 -1
  9. data/gemfiles/activerecord-5.2/Gemfile.base +4 -0
  10. data/gemfiles/activerecord-5.2/Gemfile.mysql2 +10 -0
  11. data/gemfiles/activerecord-5.2/Gemfile.postgresql +10 -0
  12. data/gemfiles/{activerecord-4.2 → activerecord-5.2}/Gemfile.sqlite3 +3 -3
  13. data/gemfiles/activerecord-6.0/Gemfile.base +4 -0
  14. data/gemfiles/activerecord-6.0/Gemfile.mysql2 +10 -0
  15. data/gemfiles/activerecord-6.0/Gemfile.postgresql +10 -0
  16. data/gemfiles/{activerecord-5.0 → activerecord-6.0}/Gemfile.sqlite3 +3 -3
  17. data/gemfiles/activerecord-6.1/Gemfile.base +4 -0
  18. data/gemfiles/activerecord-6.1/Gemfile.mysql2 +10 -0
  19. data/gemfiles/activerecord-6.1/Gemfile.postgresql +10 -0
  20. data/gemfiles/activerecord-6.1/Gemfile.sqlite3 +10 -0
  21. data/gemfiles/activerecord-7.0/Gemfile.base +4 -0
  22. data/gemfiles/activerecord-7.0/Gemfile.mysql2 +10 -0
  23. data/gemfiles/activerecord-7.0/Gemfile.postgresql +10 -0
  24. data/gemfiles/activerecord-7.0/Gemfile.sqlite3 +10 -0
  25. data/init.rb +2 -0
  26. data/lib/schema_associations/active_record/associations.rb +34 -8
  27. data/lib/schema_associations/version.rb +3 -1
  28. data/lib/schema_associations.rb +2 -0
  29. data/schema_associations.gemspec +23 -23
  30. data/schema_dev.yml +8 -6
  31. data/spec/association_spec.rb +176 -144
  32. data/spec/spec_helper.rb +4 -13
  33. metadata +58 -46
  34. data/.travis.yml +0 -25
  35. data/gemfiles/activerecord-4.2/Gemfile.base +0 -3
  36. data/gemfiles/activerecord-4.2/Gemfile.mysql2 +0 -10
  37. data/gemfiles/activerecord-4.2/Gemfile.postgresql +0 -10
  38. data/gemfiles/activerecord-5.0/Gemfile.base +0 -3
  39. data/gemfiles/activerecord-5.0/Gemfile.mysql2 +0 -10
  40. data/gemfiles/activerecord-5.0/Gemfile.postgresql +0 -10
  41. data/spec/schema_associations.sqlite3 +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c080f0a0fd14c82a61269dc1eb6e1e111ed1c331
4
- data.tar.gz: 6e0a834bf340751c07ec3614ca34a712c35e884e
2
+ SHA256:
3
+ metadata.gz: ec0cfbd6657715659bd5a2d60d2b9c149952d84be81e0f6ca966fe29d28abb01
4
+ data.tar.gz: '0873c33c130ceebf4b01d5e3eebdc764810a8c11a0666172db16e5a08817a92d'
5
5
  SHA512:
6
- metadata.gz: 06b8e5871f6cb1ee9751571a739a05560c2f5f6d787450e3c69d893e3fa2cb43875778e1f7022c6d5436baba937ddbb29e903bba0de1798904bb7743c9fa3328
7
- data.tar.gz: 4101db526873abab3e101e0bf8852f55372c272fe9c116169243a676d278455defe4c18b752c6fcf71d6ba99c54154084fe8dc851b792bb2af8aa5b860d8ddc4
6
+ metadata.gz: a1c51343a4da26da68aea83231d7e9af020acb330822cb8a4c0c969af53dd47266c0d1f5d9ff2f9b85f66fc6494a679ae9428d8be2263502ee375a95f6a1d25e
7
+ data.tar.gz: 7ea061fa8ca06101f34dae365fbed8f0a6ef292c99eb8abc99b21d9b0358ed282af2fba92061598037090d425efc07c1a63cbc6909b3524c3218ba3d5128d0b8
@@ -0,0 +1,173 @@
1
+ # This file was auto-generated by the schema_dev tool, based on the data in
2
+ # ./schema_dev.yml
3
+ # Please do not edit this file; any changes will be overwritten next time
4
+ # schema_dev gets run.
5
+ ---
6
+ name: CI PR Builds
7
+ 'on':
8
+ push:
9
+ branches:
10
+ - master
11
+ pull_request:
12
+ concurrency:
13
+ group: ci-${{ github.ref }}
14
+ cancel-in-progress: true
15
+ jobs:
16
+ test:
17
+ runs-on: ubuntu-latest
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ ruby:
22
+ - '2.5'
23
+ - '2.7'
24
+ - '3.0'
25
+ - '3.1'
26
+ activerecord:
27
+ - '5.2'
28
+ - '6.0'
29
+ - '6.1'
30
+ - '7.0'
31
+ db:
32
+ - mysql2
33
+ - sqlite3
34
+ - skip
35
+ dbversion:
36
+ - skip
37
+ exclude:
38
+ - ruby: '3.0'
39
+ activerecord: '5.2'
40
+ - ruby: '3.1'
41
+ activerecord: '5.2'
42
+ - ruby: '2.5'
43
+ activerecord: '7.0'
44
+ - db: skip
45
+ dbversion: skip
46
+ include:
47
+ - ruby: '2.5'
48
+ activerecord: '5.2'
49
+ db: postgresql
50
+ dbversion: '9.6'
51
+ - ruby: '2.5'
52
+ activerecord: '6.0'
53
+ db: postgresql
54
+ dbversion: '9.6'
55
+ - ruby: '2.5'
56
+ activerecord: '6.1'
57
+ db: postgresql
58
+ dbversion: '9.6'
59
+ - ruby: '2.7'
60
+ activerecord: '5.2'
61
+ db: postgresql
62
+ dbversion: '9.6'
63
+ - ruby: '2.7'
64
+ activerecord: '6.0'
65
+ db: postgresql
66
+ dbversion: '9.6'
67
+ - ruby: '2.7'
68
+ activerecord: '6.1'
69
+ db: postgresql
70
+ dbversion: '9.6'
71
+ - ruby: '2.7'
72
+ activerecord: '7.0'
73
+ db: postgresql
74
+ dbversion: '9.6'
75
+ - ruby: '3.0'
76
+ activerecord: '6.0'
77
+ db: postgresql
78
+ dbversion: '9.6'
79
+ - ruby: '3.0'
80
+ activerecord: '6.1'
81
+ db: postgresql
82
+ dbversion: '9.6'
83
+ - ruby: '3.0'
84
+ activerecord: '7.0'
85
+ db: postgresql
86
+ dbversion: '9.6'
87
+ - ruby: '3.1'
88
+ activerecord: '6.0'
89
+ db: postgresql
90
+ dbversion: '9.6'
91
+ - ruby: '3.1'
92
+ activerecord: '6.1'
93
+ db: postgresql
94
+ dbversion: '9.6'
95
+ - ruby: '3.1'
96
+ activerecord: '7.0'
97
+ db: postgresql
98
+ dbversion: '9.6'
99
+ env:
100
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
101
+ MYSQL_DB_HOST: 127.0.0.1
102
+ MYSQL_DB_USER: root
103
+ MYSQL_DB_PASS: database
104
+ POSTGRESQL_DB_HOST: 127.0.0.1
105
+ POSTGRESQL_DB_USER: schema_plus_test
106
+ POSTGRESQL_DB_PASS: database
107
+ steps:
108
+ - uses: actions/checkout@v2
109
+ - name: Set up Ruby
110
+ uses: ruby/setup-ruby@v1
111
+ with:
112
+ ruby-version: "${{ matrix.ruby }}"
113
+ bundler-cache: true
114
+ - name: Run bundle update
115
+ run: bundle update
116
+ - name: Start Mysql
117
+ if: matrix.db == 'mysql2'
118
+ run: |
119
+ docker run --rm --detach \
120
+ -e MYSQL_ROOT_PASSWORD=$MYSQL_DB_PASS \
121
+ -p 3306:3306 \
122
+ --health-cmd "mysqladmin ping --host=127.0.0.1 --password=$MYSQL_DB_PASS --silent" \
123
+ --health-interval 5s \
124
+ --health-timeout 5s \
125
+ --health-retries 5 \
126
+ --name database mysql:5.6
127
+ - name: Start Postgresql
128
+ if: matrix.db == 'postgresql'
129
+ run: |
130
+ docker run --rm --detach \
131
+ -e POSTGRES_USER=$POSTGRESQL_DB_USER \
132
+ -e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \
133
+ -p 5432:5432 \
134
+ --health-cmd "pg_isready -q" \
135
+ --health-interval 5s \
136
+ --health-timeout 5s \
137
+ --health-retries 5 \
138
+ --name database postgres:${{ matrix.dbversion }}
139
+ - name: Wait for database to start
140
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
141
+ run: |
142
+ COUNT=0
143
+ ATTEMPTS=20
144
+ until [[ $COUNT -eq $ATTEMPTS ]]; do
145
+ [ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
146
+ echo $(( COUNT++ )) > /dev/null
147
+ sleep 2
148
+ done
149
+ - name: Create testing database
150
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
151
+ run: bundle exec rake create_ci_database
152
+ - name: Run tests
153
+ run: bundle exec rake spec
154
+ - name: Shutdown database
155
+ if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
156
+ run: docker stop database
157
+ - name: Coveralls Parallel
158
+ if: "${{ !env.ACT }}"
159
+ uses: coverallsapp/github-action@master
160
+ with:
161
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
162
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
163
+ parallel: true
164
+ finish:
165
+ needs: test
166
+ runs-on: ubuntu-latest
167
+ steps:
168
+ - name: Coveralls Finished
169
+ if: "${{ !env.ACT }}"
170
+ uses: coverallsapp/github-action@master
171
+ with:
172
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
173
+ parallel-finished: true
data/.gitignore CHANGED
@@ -25,3 +25,4 @@ tmp/
25
25
  Gemfile.lock
26
26
  gemfiles/*.lock
27
27
  gemfiles/**/*.lock
28
+ /.idea
data/.simplecov ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.configure do
4
+ enable_coverage :branch
5
+ add_filter '/spec/'
6
+
7
+ add_group 'Binaries', '/bin/'
8
+ add_group 'Libraries', '/lib/'
9
+
10
+ if ENV['CI']
11
+ require 'simplecov-lcov'
12
+
13
+ SimpleCov::Formatter::LcovFormatter.config do |c|
14
+ c.report_with_single_file = true
15
+ c.single_report_path = 'coverage/lcov.info'
16
+ end
17
+
18
+ formatter SimpleCov::Formatter::LcovFormatter
19
+ end
20
+ end
data/Gemfile CHANGED
@@ -1,2 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "http://rubygems.org"
2
4
  gemspec
5
+
6
+ gemfile_local = File.expand_path '../Gemfile.local', __FILE__
7
+ eval File.read(gemfile_local), binding, gemfile_local if File.exist? gemfile_local
data/README.md CHANGED
@@ -5,8 +5,8 @@ definitions simpler and more DRY, by automatically defining associations based
5
5
  on the database schema.
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/schema_associations.svg)](http://badge.fury.io/rb/schema_associations)
8
- [![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_associations.svg)](http://travis-ci.org/SchemaPlus/schema_associations)
9
- [![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_associations.svg)](https://coveralls.io/r/SchemaPlus/schema_associations?branch=master)
8
+ [![Build Status](https://github.com/SchemaPlus/schema_associations/actions/workflows/pr.yml/badge.svg)](http://github.com/SchemaPlus/schema_associations/actions)
9
+ [![Coverage Status](https://coveralls.io/github/SchemaPlus/schema_associations/badge.svg)](https://coveralls.io/github/SchemaPlus/schema_associations)
10
10
 
11
11
 
12
12
  ## Overview
@@ -205,7 +205,7 @@ If your forward relation is named "parent", SchemaAssociations names the
205
205
  reverse relation "child" or "children". That is, if you have:
206
206
 
207
207
  ```ruby
208
- create_table :nodes
208
+ create_table :nodes do |t|
209
209
  t.integer :parent_id # schema_plus assumes it's a reference to this table
210
210
  end
211
211
  ```
@@ -225,14 +225,14 @@ For modularity in your tables and classes, you might use a common prefix for
225
225
  related objects. For example, you may have widgets each of which has a color, and each widget might have one frob that has a top color and a bottom color--all from the same set of colors.
226
226
 
227
227
  ```ruby
228
- create_table :widget_colors |t|
228
+ create_table :widget_colors do |t|
229
229
  end
230
230
 
231
231
  create_table :widgets do |t|
232
232
  t.integer :widget_color_id
233
233
  end
234
234
 
235
- create_table :widget_frobs
235
+ create_table :widget_frobs do |t|
236
236
  t.integer :widget_id, index: :unique
237
237
  t.integer :top_widget_color_id, references: :widget_colors
238
238
  t.integer :bottom_widget_color_id, references: :widget_colors
@@ -418,13 +418,25 @@ SchemaAssociations is tested on all combinations of:
418
418
 
419
419
  <!-- SCHEMA_DEV: MATRIX - begin -->
420
420
  <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
421
- * ruby **2.3.1** with activerecord **4.2**, using **mysql2**, **postgresql** or **sqlite3**
422
- * ruby **2.3.1** with activerecord **5.0**, using **mysql2**, **postgresql** or **sqlite3**
421
+ * ruby **2.5** with activerecord **5.2**, using **mysql2**, **postgresql:9.6** or **sqlite3**
422
+ * ruby **2.5** with activerecord **6.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
423
+ * ruby **2.5** with activerecord **6.1**, using **mysql2**, **postgresql:9.6** or **sqlite3**
424
+ * ruby **2.7** with activerecord **5.2**, using **mysql2**, **postgresql:9.6** or **sqlite3**
425
+ * ruby **2.7** with activerecord **6.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
426
+ * ruby **2.7** with activerecord **6.1**, using **mysql2**, **postgresql:9.6** or **sqlite3**
427
+ * ruby **2.7** with activerecord **7.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
428
+ * ruby **3.0** with activerecord **6.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
429
+ * ruby **3.0** with activerecord **6.1**, using **mysql2**, **postgresql:9.6** or **sqlite3**
430
+ * ruby **3.0** with activerecord **7.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
431
+ * ruby **3.1** with activerecord **6.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
432
+ * ruby **3.1** with activerecord **6.1**, using **mysql2**, **postgresql:9.6** or **sqlite3**
433
+ * ruby **3.1** with activerecord **7.0**, using **mysql2**, **postgresql:9.6** or **sqlite3**
423
434
 
424
435
  <!-- SCHEMA_DEV: MATRIX - end -->
425
436
 
426
437
  Notes:
427
438
 
439
+ * As for version 1.3.0, rails < 5.2 and ruby < 2.5 are no longer supported
428
440
  * As of version 1.2.3, rails < 4.1 and ruby < 2.1 are no longer supported
429
441
  * As of version 1.2.0, ruby 1.9.2 is no longer supported.
430
442
  * As of version 1.0.0, ruby 1.8.7 and rails < 3.2 are no longer supported.
@@ -439,20 +451,24 @@ or in a Gemfile
439
451
 
440
452
  gem "schema_associations"
441
453
 
442
- ## Testing
454
+ ## Release notes:
443
455
 
444
- SchemaAssociations is tested against the matrix of combinations. To run the full combo of
445
- tests, after you've forked & cloned:
456
+ ### 1.4.0
446
457
 
447
- $ cd schema_associations
448
- $ schema_dev bundle install
449
- $ schema_dev rspec
458
+ * Add AR 6.1 and 7.0
459
+ * Add Ruby 3.1
460
+ * drop schema_plus_compatibiltiy dependency (indirect through schema_plus_foreign_keys update)
450
461
 
451
- For more info, see [schema_dev](https://github.com/SchemaPlus/schema_dev)
462
+ ### 1.3.0
452
463
 
453
- Code coverage results will be in coverage/index.html -- it should be at 100% coverage.
464
+ * add AR 6.0
465
+ * add Ruby 3.0
466
+ * drop AR < 5.2
467
+ * drop Ruby < 2.5
454
468
 
455
- ## Release notes:
469
+ ### 1.2.7
470
+
471
+ * add in auto deferring of has_* :through associations manually defined on the model so they work in AR 5.1+
456
472
 
457
473
  ### 1.2.6
458
474
 
@@ -514,3 +530,28 @@ Code coverage results will be in coverage/index.html -- it should be at 100% cov
514
530
  ## License
515
531
 
516
532
  This gem is released under the MIT license.
533
+
534
+ ## Development & Testing
535
+
536
+ Are you interested in contributing to SchemaPlus::Views? Thanks! Please follow the standard protocol: fork, feature branch, develop, push, and issue pull request.
537
+
538
+ Some things to know about to help you develop and test:
539
+
540
+ <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - begin -->
541
+ <!-- These lines are auto-inserted from a schema_dev template -->
542
+ * **schema_dev**: SchemaAssociations uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
543
+ facilitate running rspec tests on the matrix of ruby, activerecord, and database
544
+ versions that the gem supports, both locally and on
545
+ [github actions](https://github.com/SchemaPlus/schema_associations/actions)
546
+
547
+ To to run rspec locally on the full matrix, do:
548
+
549
+ $ schema_dev bundle install
550
+ $ schema_dev rspec
551
+
552
+ You can also run on just one configuration at a time; For info, see `schema_dev --help` or the [schema_dev](https://github.com/SchemaPlus/schema_dev) README.
553
+
554
+ The matrix of configurations is specified in `schema_dev.yml` in
555
+ the project root.
556
+
557
+ <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
data/Rakefile CHANGED
@@ -1,20 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
4
- require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec)
6
-
7
6
  require 'schema_dev/tasks'
8
7
 
9
-
10
8
  task :default => :spec
11
9
 
12
- require 'rdoc/task'
13
- Rake::RDocTask.new do |rdoc|
14
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
15
-
16
- rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = "schema_associations #{version}"
18
- rdoc.rdoc_files.include('README*')
19
- rdoc.rdoc_files.include('lib/**/*.rb')
20
- end
10
+ require 'rspec/core/rake_task'
11
+ RSpec::Core::RakeTask.new(:spec)
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- gemspec :path => File.expand_path('..', __FILE__)
2
+ gemspec path: File.expand_path('..', __FILE__)
3
3
 
4
4
  File.exist?(gemfile_local = File.expand_path('../Gemfile.local', __FILE__)) and eval File.read(gemfile_local), binding, gemfile_local
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 5.2.0.beta0", "< 5.3"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "mysql2"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -1,5 +1,5 @@
1
- require "pathname"
2
- eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
3
 
4
4
  platform :ruby do
5
5
  gem "sqlite3"
@@ -7,4 +7,4 @@ end
7
7
 
8
8
  platform :jruby do
9
9
  gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
- end
10
+ end
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 6.0", "< 6.1"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "mysql2"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -1,5 +1,5 @@
1
- require "pathname"
2
- eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
3
 
4
4
  platform :ruby do
5
5
  gem "sqlite3"
@@ -7,4 +7,4 @@ end
7
7
 
8
8
  platform :jruby do
9
9
  gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
- end
10
+ end
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 6.1", "< 6.2"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "mysql2"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 7.0", "< 7.1"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "mysql2"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
data/init.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'schema_associations' unless defined?(SchemaAssociations)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ostruct'
2
4
 
3
5
  module SchemaAssociations
@@ -5,7 +7,7 @@ module SchemaAssociations
5
7
 
6
8
  module Relation
7
9
 
8
- def initialize(klass, *args)
10
+ def initialize(klass, *args, **kwargs)
9
11
  klass.send :_load_schema_associations_associations unless klass.nil?
10
12
  super
11
13
  end
@@ -15,6 +17,11 @@ module SchemaAssociations
15
17
 
16
18
  module ClassMethods
17
19
 
20
+ def reflections(*args)
21
+ _load_schema_associations_associations
22
+ super
23
+ end
24
+
18
25
  def reflect_on_association(*args)
19
26
  _load_schema_associations_associations
20
27
  super
@@ -57,7 +64,6 @@ module SchemaAssociations
57
64
  # schema_associations :concise_names => false, :except_type => :has_and_belongs_to_many
58
65
  # end
59
66
  #
60
- #
61
67
  def schema_associations(opts={})
62
68
  @schema_associations_config = SchemaAssociations.config.merge({:auto_create => true}.merge(opts))
63
69
  end
@@ -66,6 +72,17 @@ module SchemaAssociations
66
72
  @schema_associations_config ||= SchemaAssociations.config.dup
67
73
  end
68
74
 
75
+ %i[has_many has_one].each do |m|
76
+ define_method(m) do |name, *args, **options|
77
+ if @schema_associations_associations_loaded
78
+ super name, *args, **options
79
+ else
80
+ @schema_associations_deferred_associations ||= []
81
+ @schema_associations_deferred_associations.push({macro: m, name: name, args: args, options: options})
82
+ end
83
+ end
84
+ end
85
+
69
86
  private
70
87
 
71
88
  def _load_schema_associations_associations
@@ -73,6 +90,8 @@ module SchemaAssociations
73
90
  return if abstract_class?
74
91
  return unless schema_associations_config.auto_create?
75
92
 
93
+ @schema_associations_associations_loaded = :loading
94
+
76
95
  reverse_foreign_keys.each do | foreign_key |
77
96
  if foreign_key.from_table =~ /^#{table_name}_(.*)$/ || foreign_key.from_table =~ /^(.*)_#{table_name}$/
78
97
  other_table = $1
@@ -90,6 +109,14 @@ module SchemaAssociations
90
109
  _define_association(:belongs_to, foreign_key)
91
110
  end
92
111
 
112
+ (@schema_associations_deferred_associations || []).each do |a|
113
+ argstr = a[:args].inspect[1...-1] + ' # deferred association'
114
+ _create_association(a[:macro], a[:name], argstr, *a[:args], **a[:options])
115
+ end
116
+ if instance_variable_defined? :@schema_associations_deferred_associations
117
+ remove_instance_variable :@schema_associations_deferred_associations
118
+ end
119
+
93
120
  @schema_associations_associations_loaded = true
94
121
  end
95
122
 
@@ -145,21 +172,20 @@ module SchemaAssociations
145
172
  end
146
173
  argstr += opts.inspect[1...-1]
147
174
  if (_filter_association(macro, name) && !_method_exists?(name))
148
- _create_association(macro, name, argstr, scope_block, opts.dup)
175
+ _create_association(macro, name, argstr, scope_block, **opts.dup)
149
176
  end
150
177
  end
151
178
 
152
- def _create_association(macro, name, argstr, *args)
179
+ def _create_association(macro, name, argstr, *args, **options)
153
180
  logger.debug "[schema_associations] #{self.name || self.from_table.classify}.#{macro} #{name.inspect}, #{argstr}"
154
- send macro, name, *args
181
+ send macro, name, *args, **options
155
182
  case
156
183
  when respond_to?(:subclasses) then subclasses
157
184
  end.each do |subclass|
158
- subclass.send :_create_association, macro, name, argstr, *args
185
+ subclass.send :_create_association, macro, name, argstr, *args, **options
159
186
  end
160
187
  end
161
188
 
162
-
163
189
  def _determine_association_names(reference_name, referencing_name, references_name)
164
190
 
165
191
  references_concise = _concise_name(references_name, referencing_name)
@@ -248,7 +274,7 @@ module SchemaAssociations
248
274
  end
249
275
 
250
276
  def _method_exists?(name)
251
- method_defined?(name) || private_method_defined?(name) and not (name == :type && [Object, Kernel].include?(instance_method(:type).owner))
277
+ method_defined?(name) || private_method_defined?(name)
252
278
  end
253
279
 
254
280
  end