Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
amitsuryavanshi committed Jan 4, 2022
1 parent efb44b0 commit 1a77b92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/active_graph/node/query/query_proxy_eager_loading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def perform_query
record = cache_and_init(record, with_associations_tree)
eager_data.zip(with_associations_tree.paths.map(&:last)).each do |eager_records, element|
eager_records.each do |eager_record|
next unless eager_record.first && eager_record.first.type.to_s == element.association.relationship_type.to_s
next unless eager_record.first&.type&.to_s == element.association.relationship_type.to_s
add_to_cache(*eager_record, element)
end
end
Expand Down Expand Up @@ -137,7 +137,7 @@ def with_association_query_part(base_query, path, previous_with_vars)
end

def relationship_collection(path)
path.last.rel_length ? "last(relationships(#{escape("#{path_name(path)}_path")}))" : "#{escape("#{path_name(path)}_rel")}"
path.last.rel_length ? "last(relationships(#{escape("#{path_name(path)}_path")}))" : escape("#{path_name(path)}_rel")
end

def optional_match_with_where(base_query, path, _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ def add_spec_and_validate(spec)
end

def validate_for_zero_length_paths
fail 'Can not eager load more than one zero length path.' if values.count { |value| value.zero_length_path? } > 1
fail 'Can not eager load more than one zero length path.' if values.count(&:zero_length_path?) > 1
end

def zero_length_path?
rel_length&.fetch(:min, nil)&.to_s == '0' ||
values.any? { |value| value.zero_length_path? }
rel_length&.fetch(:min, nil)&.to_s == '0' || values.any?(&:zero_length_path?)
end

def add_spec(spec)
Expand Down

0 comments on commit 1a77b92

Please sign in to comment.