Skip to content

Commit

Permalink
Fixes preload_scope when association is polymorphic
Browse files Browse the repository at this point in the history
Presently, the `preload_scope` check fails because
`model.reflect_on_association(assocation).klass` will never be valid for
polymorphic associations.

This raises an ArgumentError if the association is polymorphic and
preload_scope is applied, but in all other ways it behaves the same.e
  • Loading branch information
bbugh committed May 20, 2018
1 parent add2d25 commit 71322c7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/graphql/preload/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def perform(records)
end

private def preload_scope
scope if scope.try(:klass) == model.reflect_on_association(association).klass
return nil unless scope
reflection = model.reflect_on_association(association)
raise ArgumentError, 'Cannot specify preload_scope for polymorphic associations' if reflection.polymorphic?
scope if scope.try(:klass) == reflection.klass
end

private def validate_association
Expand Down

0 comments on commit 71322c7

Please sign in to comment.