Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reload macro to include method in docs #499

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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