Skip to content

Instantly share code, notes, and snippets.

@paulcsmith
Last active July 30, 2018 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulcsmith/5826c700d9b2e491bc04bf461bb8a218 to your computer and use it in GitHub Desktop.
Save paulcsmith/5826c700d9b2e491bc04bf461bb8a218 to your computer and use it in GitHub Desktop.
# Lucky will let you know at runtime that `comment.author` was not preloaded
CommentQuery.new.each do |comment|
p comment.author.name
end
# This will work since we preloaded the author
CommentQuery.new.preload_author.each do |comment|
p comment.author.name
end
# Use author! to skip preloading and skip raising the runtime error
CommentQuery.new.each do |comment|
p comment.author!.name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment