docs: Clarify resource code in Actions guide (#1156)

This commit is contained in:
Rebecca Le 2024-05-13 19:30:59 +08:00 committed by GitHub
parent 12de8d19a5
commit 6afd9f57f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -98,7 +98,9 @@ end
# in the resource
defaults [:read, ...]
actions do
defaults [:read, ...]
end
```
And here is the "right way", where the rules about getting the top tickets have been moved into the resource as a nicely named action, and included in the `code_interface` of that resource. The reality of the situation is that `top_tickets/1` is meant to be obsoleted by your Ash resource! Here is how it _should_ be done.
@ -110,7 +112,8 @@ code_interface do
define :top, args: [:user_id]
end
read :top do
actions do
read :top do
argument :user_id, :uuid do
allow_nil? false
end
@ -118,6 +121,7 @@ read :top do
prepare build(limit: 10, sort: [opened_at: :desc])
filter expr(priority in [:medium, :high] and representative_id == ^arg(:user_id) and status == :open)
end
end
```