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: f437b6601b911a6dc53a3e9a87ef86a44c031bf7
4
- data.tar.gz: 01733c6190ca58c13e606371eaf445178727a87c
3
+ metadata.gz: dfe28e0adc2389fd4eba4a34fcffc653b24881dd
4
+ data.tar.gz: 52bd83f5aa95550d1d781ffe846a0d7baa4e8d32
5
5
  SHA512:
6
- metadata.gz: f129529340548f1f9dec261bb9f8fced68425adb513c936b5ccbe85e789db6b860f092099e83a48d4584de05ddb42e95349f713f8ac67faf8a86f2923ec3de0c
7
- data.tar.gz: 39b22ccbcb98ba60478cdc9a5ee7b2f034948b4a5bb4b4a1202df2d239587e067bee18493c8ee9b9fd1cc39c3db817f8b8ec650c884b1ff908d2e5db16004277
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
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordCustomPreloader
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_custom_preloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich