active_record_custom_preloader 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfe28e0adc2389fd4eba4a34fcffc653b24881dd
|
4
|
+
data.tar.gz: 52bd83f5aa95550d1d781ffe846a0d7baa4e8d32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a44e4fd6a2862eeaf8f2899ce042de426067d97ee769a5576ead5826c63a7196a9174dbdbd7a992b1770a0489f4516708c34f95f74dc0371d8a2e7abfeb8d54b
|
7
|
+
data.tar.gz: 58d9b09c98ae5c198368e0e42606c30ef11d7337c741f2337b437b375108b053a4936128f317b558831f56605b1539e77fc3de209da94289c6ad68e90c07b788
|
@@ -5,6 +5,7 @@ require 'active_record_custom_preloader/associations_preloader'
|
|
5
5
|
require 'active_record_custom_preloader/model_patch'
|
6
6
|
require 'active_record_custom_preloader/relation_patch'
|
7
7
|
require 'active_record_custom_preloader/with_multiple_foreign_keys_loading'
|
8
|
+
require 'active_record_custom_preloader/with_array_foreign_keys_loading'
|
8
9
|
|
9
10
|
module ActiveRecordCustomPreloader
|
10
11
|
class Error < StandardError
|
@@ -45,13 +45,14 @@ module ActiveRecordCustomPreloader
|
|
45
45
|
# array for has_many and model or nil for has_one.
|
46
46
|
def associations_by_parent_record(parent_record, association_records)
|
47
47
|
ids = parent_record.public_send(association_foreign_keys_name)
|
48
|
+
return [] if ids.nil? || ids.empty?
|
48
49
|
result = association_records.select { |r| ids.include?(r.id) }
|
49
50
|
result.sort_by! { |r| ids.index r.id } if keep_sorting
|
50
51
|
result
|
51
52
|
end
|
52
53
|
|
53
54
|
def fetch_association(parent_records)
|
54
|
-
ids = parent_records.map(&association_foreign_keys_name).flatten.uniq
|
55
|
+
ids = parent_records.map(&association_foreign_keys_name).flatten.uniq.compact
|
55
56
|
associations_scope.where(id: ids).to_a
|
56
57
|
end
|
57
58
|
|