Skip to content

Commit

Permalink
[test*]. adds check to not preload again
Browse files Browse the repository at this point in the history
  • Loading branch information
David Yee authored and David Yee committed Aug 12, 2022
1 parent a3d6a52 commit 96e2087
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/blueprinter/helpers/base_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def object_relation_to_hash(local_options, object, view_name)
field_to_association_hash = get_field_to_association_hash(object)
list_of_associations_to_preload = []
view_collection.fields_for(view_name).each do |field|
if field_to_association_hash.key?(field.name) &&
!list_of_associations_to_preload.include?(field_to_association_hash[field.name])
if preload_field?(field, field_to_association_hash, list_of_associations_to_preload, object)
list_of_associations_to_preload << field_to_association_hash[field.name]
end
end
Expand All @@ -65,6 +64,13 @@ def object_relation_to_hash(local_options, object, view_name)
end
end

def preload_field?(field, field_to_association_hash, list_of_associations_to_preload, object)
field_to_association_hash.key?(field.name) &&
!list_of_associations_to_preload.include?(field_to_association_hash[field.name]) &&
object.size > 0 &&
!object.first.association(field_to_association_hash[field.name]).loaded?
end

def prepend_root_and_meta(data, root, meta)
return data unless root
ret = {root => data}
Expand Down

0 comments on commit 96e2087

Please sign in to comment.