dynamic-active-model-rails 1.3.1 → 1.4.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: 34dff3922cd01d038ce4fb713b439e1f3b3437fda3dc922dd2267265c12f706c
|
|
4
|
+
data.tar.gz: 56830cd57bc3525a1f810974c278391967d9ae728027cfb6926298bec52d8077
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52e56cfa88383d6fc9a7b1a2f7f3f09657a10bb72342a7ed38f4c886ba163e8c21c2c5ab47dcaa0cc2ac8434f95bb7af116027a0a2fd6b50132dbc54a00da48e
|
|
7
|
+
data.tar.gz: f208cda1b1741f08cb946038c87f9ae472d532f2ddc906085c7209aa89c71b5d2e74fe7a0daa002fa6b3d893a3efa94bb5c7ada6d1da865b3bde12e1f59deac2
|
data/README.md
CHANGED
|
@@ -98,6 +98,7 @@ The `cars_db` → `CarsDB` mapping is registered with the Rails autoloader only,
|
|
|
98
98
|
| `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`. |
|
|
99
99
|
| `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. |
|
|
100
100
|
| `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. |
|
|
101
|
+
| `optional_belongs_to:` | `false` | Make every `belongs_to` optional, including those on `NOT NULL` foreign keys, so saving a record doesn't check that its parent exists. For code that writes rows whose parents may be missing. See the core README. |
|
|
101
102
|
| `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. |
|
|
102
103
|
| `extensions_suffix:` | `'.ext.rb'` | Suffix of extension files. The autoloader ignores files with this suffix. |
|
|
103
104
|
|
|
@@ -35,6 +35,9 @@ module DynamicActiveModel
|
|
|
35
35
|
# @return [Boolean] Whether to also add has_many :through across join models
|
|
36
36
|
attr_reader :has_many_through
|
|
37
37
|
|
|
38
|
+
# @return [Boolean] Whether every belongs_to is optional, even on NOT NULL foreign keys
|
|
39
|
+
attr_reader :optional_belongs_to
|
|
40
|
+
|
|
38
41
|
# @return [Hash] Custom relationship names by table and foreign key
|
|
39
42
|
attr_reader :relationships
|
|
40
43
|
|
|
@@ -53,16 +56,19 @@ module DynamicActiveModel
|
|
|
53
56
|
# @param foreign_key_constraints [Boolean] Also relate columns through the database's
|
|
54
57
|
# foreign key constraints
|
|
55
58
|
# @param has_many_through [Boolean] Also add has_many :through across join models
|
|
59
|
+
# @param optional_belongs_to [Boolean] Make every belongs_to optional, even on NOT NULL
|
|
60
|
+
# foreign keys, so saves don't validate the parent exists
|
|
56
61
|
# @raise [ArgumentError] If both a connection and connects_to are given
|
|
57
62
|
def initialize(name, connection = nil, module_name: nil, parent_class: 'ApplicationRecord',
|
|
58
63
|
extensions_path: nil, extensions_suffix: '.ext.rb', connects_to: nil,
|
|
59
|
-
foreign_key_constraints: false, has_many_through: false)
|
|
64
|
+
foreign_key_constraints: false, has_many_through: false, optional_belongs_to: false)
|
|
60
65
|
raise ArgumentError, 'pass either a connection or connects_to:, not both' if connection && connects_to
|
|
61
66
|
|
|
62
67
|
@connection = connection
|
|
63
68
|
@connects_to = connects_to && normalize_connects_to(connects_to)
|
|
64
69
|
@foreign_key_constraints = foreign_key_constraints
|
|
65
70
|
@has_many_through = has_many_through
|
|
71
|
+
@optional_belongs_to = optional_belongs_to
|
|
66
72
|
@module_name = module_name || default_module_name(name)
|
|
67
73
|
@parent_class_name = parent_class.to_s
|
|
68
74
|
@extensions_path = extensions_path&.to_s
|
|
@@ -63,7 +63,8 @@ module DynamicActiveModel
|
|
|
63
63
|
@database.create_models!
|
|
64
64
|
Explorer.build_relationships!(@database, definition.relationships,
|
|
65
65
|
foreign_key_constraints: definition.foreign_key_constraints,
|
|
66
|
-
has_many_through: definition.has_many_through
|
|
66
|
+
has_many_through: definition.has_many_through,
|
|
67
|
+
optional_belongs_to: definition.optional_belongs_to)
|
|
67
68
|
load_extensions
|
|
68
69
|
ActiveSupport.run_load_hooks(definition.load_hook, @database)
|
|
69
70
|
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.4.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.4.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.4.0
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: railties
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|