activerecord-has_some_of_many 1.2.0 → 1.2.1
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: 9e4395779eb20221279e5d0806addac5b138630f80772cc0f3d5d769c57c080b
|
|
4
|
+
data.tar.gz: 7cb9f639e03f1bbc42d98ab4eb1eb9f614721d1db185a17bbf9d131ac0c9acd0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 24dedf3565209740b76e034ef4e292edecb3d702908e875c552d48301786f7cf37952729a6907fbb18e89cd6bd768db76cce1f26eff14d2a781da57004d3593d
|
|
7
|
+
data.tar.gz: e3a4da48f8a6c13ab43066c16b05931e889270e172305f095ddb3f2ae4d1a3bcdec8f48e10c8c5ff8c3238b0efa3cfb8b30b3e2f8f375c767ce473a733f10d05
|
|
@@ -11,17 +11,20 @@ module ActiveRecord
|
|
|
11
11
|
# @param [Proc, nil] scope A scope to apply to the association
|
|
12
12
|
# @param [Hash] options Additional options to pass to the association
|
|
13
13
|
def self.build(klass, association_type, name, scope = nil, **options)
|
|
14
|
-
|
|
14
|
+
# Don't resolve `klass.primary_key` here: it may query the database schema,
|
|
15
|
+
# and associations must be declarable without a database connection.
|
|
16
|
+
# Like Rails' own associations, the owner's primary key is resolved lazily.
|
|
17
|
+
primary_key = options[:primary_key]
|
|
15
18
|
foreign_key = options[:foreign_key] || ActiveSupport::Inflector.foreign_key(klass, true)
|
|
16
19
|
foreign_key_alias = options[:foreign_key_alias] || "#{foreign_key}_alias"
|
|
17
20
|
|
|
18
21
|
lateral_subselection_scope = lambda do
|
|
19
22
|
relation = scope ? instance_exec(&scope) : self
|
|
20
23
|
limit = association_type == :has_one ? 1 : nil
|
|
21
|
-
ActiveRecord::HasSomeOfMany::Associations.build_scope(klass, relation, primary_key: primary_key, foreign_key: foreign_key, foreign_key_alias: foreign_key_alias, limit: limit)
|
|
24
|
+
ActiveRecord::HasSomeOfMany::Associations.build_scope(klass, relation, primary_key: primary_key || klass.primary_key, foreign_key: foreign_key, foreign_key_alias: foreign_key_alias, limit: limit)
|
|
22
25
|
end
|
|
23
26
|
|
|
24
|
-
options[:primary_key] = primary_key
|
|
27
|
+
options[:primary_key] = primary_key if primary_key
|
|
25
28
|
options[:foreign_key] = foreign_key_alias
|
|
26
29
|
|
|
27
30
|
klass.send(association_type, name, lateral_subselection_scope, **options)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-has_some_of_many
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben Sheldon [he/him]
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-10-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|