dynamic-active-model-rails 1.1.0 → 1.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2df8e51695a6a96f2fc32f697985e96e6ae201bf52af9acffad5877d25128751
|
|
4
|
+
data.tar.gz: 3ac8715b733383d6160bf229cb234b0df74e6edb1c9220d2caeb95132e1292db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b605039cf58e47a07283d309dcc0dcbabe890314f94ee6c881b1825c26d6714ecbbc00814e119d14fcf7f3ca54b082a4ec7a1592005e39e556b57a155f5337e7
|
|
7
|
+
data.tar.gz: 660965617e683a0ae03a1b1f053590262953d5ea6cb664eeff623c6daeff5b16ed6ab41eb8b7eacdbc07c072657ee6e18fc532254a60c50258397ae721f121b5
|
data/README.md
CHANGED
|
@@ -79,6 +79,7 @@ The `cars_db` → `CarsDB` mapping is registered with the Rails autoloader only,
|
|
|
79
79
|
| `parent_class:` | `'ApplicationRecord'` | Superclass of the generated abstract base class, given as a name so it can be reloaded. |
|
|
80
80
|
| `connects_to:` | `nil` | Roles for Rails multi-database support, such as `{ writing: :cars, reading: :cars_replica }`, or `connects_to`'s own arguments (`{ database: ..., shards: ... }`). Can't be combined with a `connection`. |
|
|
81
81
|
| `foreign_key_constraints:` | `false` | Also derive associations from the database's foreign key constraints. This catches columns like `posts.author_id → users` and self-references, and costs one query per table at build time. See the core README. |
|
|
82
|
+
| `has_many_through:` | `false` | Add `has_many :through` across join models: tables with a unique index on two foreign keys, such as `user_roles`. See the core README. |
|
|
82
83
|
| `extensions_path:` | `app/models/<folder>` | Directory of extension files, absolute or relative to `Rails.root`. The default folder may be absent; a configured path must exist. |
|
|
83
84
|
| `extensions_suffix:` | `'.ext.rb'` | Suffix of extension files. The autoloader ignores files with this suffix. |
|
|
84
85
|
|
|
@@ -32,6 +32,9 @@ module DynamicActiveModel
|
|
|
32
32
|
# @return [Boolean] Whether to also relate columns through foreign key constraints
|
|
33
33
|
attr_reader :foreign_key_constraints
|
|
34
34
|
|
|
35
|
+
# @return [Boolean] Whether to also add has_many :through across join models
|
|
36
|
+
attr_reader :has_many_through
|
|
37
|
+
|
|
35
38
|
# @return [Hash] Custom relationship names by table and foreign key
|
|
36
39
|
attr_reader :relationships
|
|
37
40
|
|
|
@@ -49,15 +52,17 @@ module DynamicActiveModel
|
|
|
49
52
|
# connects_to's own arguments ({ database: ..., shards: ... })
|
|
50
53
|
# @param foreign_key_constraints [Boolean] Also relate columns through the database's
|
|
51
54
|
# foreign key constraints
|
|
55
|
+
# @param has_many_through [Boolean] Also add has_many :through across join models
|
|
52
56
|
# @raise [ArgumentError] If both a connection and connects_to are given
|
|
53
57
|
def initialize(name, connection = nil, module_name: nil, parent_class: 'ApplicationRecord',
|
|
54
58
|
extensions_path: nil, extensions_suffix: '.ext.rb', connects_to: nil,
|
|
55
|
-
foreign_key_constraints: false)
|
|
59
|
+
foreign_key_constraints: false, has_many_through: false)
|
|
56
60
|
raise ArgumentError, 'pass either a connection or connects_to:, not both' if connection && connects_to
|
|
57
61
|
|
|
58
62
|
@connection = connection
|
|
59
63
|
@connects_to = connects_to && normalize_connects_to(connects_to)
|
|
60
64
|
@foreign_key_constraints = foreign_key_constraints
|
|
65
|
+
@has_many_through = has_many_through
|
|
61
66
|
@module_name = module_name || default_module_name(name)
|
|
62
67
|
@parent_class_name = parent_class.to_s
|
|
63
68
|
@extensions_path = extensions_path&.to_s
|
|
@@ -62,7 +62,8 @@ module DynamicActiveModel
|
|
|
62
62
|
@database = new_database
|
|
63
63
|
@database.create_models!
|
|
64
64
|
Explorer.build_relationships!(@database, definition.relationships,
|
|
65
|
-
foreign_key_constraints: definition.foreign_key_constraints
|
|
65
|
+
foreign_key_constraints: definition.foreign_key_constraints,
|
|
66
|
+
has_many_through: definition.has_many_through)
|
|
66
67
|
load_extensions
|
|
67
68
|
ActiveSupport.run_load_hooks(definition.load_hook, @database)
|
|
68
69
|
rescue StandardError
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dynamic-active-model-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Doug Youch
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - '='
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 1.
|
|
32
|
+
version: 1.2.0
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - '='
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 1.
|
|
39
|
+
version: 1.2.0
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: railties
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|