Skip to content

Commit

Permalink
Fix reload macro to include method in docs (#499)
Browse files Browse the repository at this point in the history
Co-authored-by: Seth T <[email protected]>
  • Loading branch information
stufro and crimson-knight authored Nov 16, 2023
1 parent d756079 commit 182f997
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/granite/querying.cr
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,19 @@ module Granite::Querying
end
end

{% if parse_type("Spec").resolve? %}
# Returns the record with the attributes reloaded from the database.
#
# **Note:** this method is only defined when the `Spec` module is present.
#
# ```
# post = Post.create(name: "Granite Rocks!", body: "Check this out.")
# # record gets updated by another process
# post.reload # performs another find to fetch the record again
# ```
def reload
{% if !@top_level.has_constant? "Spec" %}
raise "#reload is a convenience method for testing only, please use #find in your application code"
{% end %}
self.class.find!(primary_key_value)
end
{% end %}
# Returns the record with the attributes reloaded from the database.
#
# **Note:** this method is only defined when the `Spec` module is present.
#
# ```
# post = Post.create(name: "Granite Rocks!", body: "Check this out.")
# # record gets updated by another process
# post.reload # performs another find to fetch the record again
# ```
def reload
{% if !@top_level.has_constant? "Spec" %}
raise "#reload is a convenience method for testing only, please use #find in your application code"
{% end %}
self.class.find!(primary_key_value)
end
end

0 comments on commit 182f997

Please sign in to comment.