How can I delete a record by id?

Currently I can destroy a ticket with:
Helpdesk.Api.destroy_support_ticket ticket
Helpdesk.Api.destroy_support_ticket ticket
But I would like to be able to do it by ID:
Helpdesk.Api.destroy_support_ticket "5f63e748-68e0-4b7d-9030-47c38eb8e86e"
Helpdesk.Api.destroy_support_ticket "5f63e748-68e0-4b7d-9030-47c38eb8e86e"
My code:
defmodule Helpdesk.Support.Ticket do
# @link https://ash-hq.org/docs/guides/ash/latest/tutorials/get-started

# This turns this module into a resource
use Ash.Resource,
data_layer: Ash.DataLayer.Ets

actions do
# Add a set of simple actions. You'll customize these later.
defaults [:create, :read, :update, :destroy]

### ommitted code..

# @link https://ash-hq.org/docs/guides/ash/latest/code-interface
code_interface do
define :open_support_ticket, args: [:subject]
define :read_support_ticket, action: :read, get_by: [:id]
define :close_support_ticket, args: []
define :destroy_support_ticket, action: :destroy
end
end
defmodule Helpdesk.Support.Ticket do
# @link https://ash-hq.org/docs/guides/ash/latest/tutorials/get-started

# This turns this module into a resource
use Ash.Resource,
data_layer: Ash.DataLayer.Ets

actions do
# Add a set of simple actions. You'll customize these later.
defaults [:create, :read, :update, :destroy]

### ommitted code..

# @link https://ash-hq.org/docs/guides/ash/latest/code-interface
code_interface do
define :open_support_ticket, args: [:subject]
define :read_support_ticket, action: :read, get_by: [:id]
define :close_support_ticket, args: []
define :destroy_support_ticket, action: :destroy
end
end
3 Replies
ZachDaniel
ZachDaniel3y ago
Currently, you have to look the record up, or provide a “fake” one like %Resource{id: id}. Actions like that will be coming soon.
exadra37
exadra37OP3y ago
Awesome. Once more many thanks for the help.
ZachDaniel
ZachDaniel3y ago
My pleasure

Did you find this page helpful?