Skip to content
Open
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
20 changes: 19 additions & 1 deletion src/actions/guides/database/querying.cr
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,25 @@ class Guides::Database::Querying < GuideAction
author.hide_avatar #=> true
```

> The `reload` method requires a `primary_key`. `view` models that need this method will need to implement it.
If there is a chance that the record may have been deleted between the
initial load and the reload, the `reload?` variant can be used, which
returns a nilable value.

```crystal
# Safely try to reload the Author instance
if reloaded_author = author.reload?
reloaded_author.hide_avatar #=> false
end

# ... another process deletes it
DeleteAuthor.delete!(author)

# Safely try to reload the Author instance again
author.reload? #=> nil
```

> The `reload` and `reload?` methods require a `primary_key`. `view` models
that need this method will need to implement it.

### Adding preloads when reloading

Expand Down
Loading