mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 21:13:10 +12:00
docs: add code interface to generic actions guide
This commit is contained in:
parent
9e155e55c2
commit
0301009073
1 changed files with 17 additions and 1 deletions
|
@ -71,6 +71,7 @@ end
|
|||
> instance or instances of the resource. It's natural to assume that you can
|
||||
> set your action's return type to the name of your resource. This won't work
|
||||
> as resources do not define a type, unless they are embedded. In embedded resources, this won't work because the module is still being compiled, so referencing yourself as a type causes a compile error. Instead, use the `:struct` type and the `instance_of` constraint, like so:
|
||||
>
|
||||
> ```elixir
|
||||
> action :get, :struct do
|
||||
> constraints instance_of: __MODULE__
|
||||
|
@ -108,4 +109,19 @@ Call this action:
|
|||
|> Ash.run_action()
|
||||
|
||||
IO.puts(greeting) # Output: Hello: Alice
|
||||
```
|
||||
```
|
||||
|
||||
### Using Code Interface
|
||||
|
||||
You can also use [Code Interfaces](documentation/topics/resources/code-interfaces.md) to call actions:
|
||||
|
||||
Given a definition like:
|
||||
|
||||
```elixir
|
||||
define :say_hello, args: [:name]
|
||||
```
|
||||
|
||||
```elixir
|
||||
{:ok, greeting} = Resource.say_hello("Alice")
|
||||
greeting = Resource.say_hello!("Alice")
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue