-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
create.ex
106 lines (101 loc) · 3.55 KB
/
create.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
defmodule Ash.Resource.Actions.Create do
@moduledoc "Represents a create action on a resource."
defstruct [
:name,
:primary?,
:description,
:error_handler,
accept: nil,
manual: nil,
touches_resources: [],
require_attributes: [],
delay_global_validations?: false,
skip_global_validations?: false,
upsert?: false,
upsert_identity: nil,
upsert_fields: nil,
arguments: [],
changes: [],
allow_nil_input: [],
reject: [],
metadata: [],
transaction?: true,
type: :create
]
@type t :: %__MODULE__{
type: :create,
name: atom,
accept: list(atom),
manual: module | nil,
upsert?: boolean,
delay_global_validations?: boolean,
skip_global_validations?: boolean,
upsert_identity: atom | nil,
upsert_fields:
nil
| list(atom)
| :replace_all
| {:replace, list(atom)}
| {:replace_all_except, list(atom)},
allow_nil_input: list(atom),
touches_resources: list(atom),
arguments: list(Ash.Resource.Actions.Argument.t()),
primary?: boolean,
description: String.t() | nil
}
import Ash.Resource.Actions.SharedOptions
@global_opts shared_options()
@create_update_opts create_update_opts()
@opt_schema [
allow_nil_input: [
type: {:list, :atom},
doc: """
A list of attributes that would normally be required, but should not be for this action. They will still be validated just before the record is created.
"""
],
manual: [
type:
{:spark_function_behaviour, Ash.Resource.ManualCreate,
{Ash.Resource.ManualCreate.Function, 2}},
doc: """
Override the creation behavior. Accepts a module or module and opts, or a function that takes the changeset and context. See the [manual actions guide](/documentation/topics/manual-actions.md) for more.
"""
],
upsert?: [
type: :boolean,
default: false,
doc: """
Forces all uses of this action to be treated as an upsert.
"""
],
upsert_identity: [
type: :atom,
doc: """
The identity to use for the upsert. Cannot be overriden by the caller. Ignored if `upsert?` is not set to `true`.
"""
],
upsert_fields: [
type:
{:or,
[
{:literal, :replace_all},
{:tuple, [{:literal, :replace}, {:wrap_list, :atom}]},
{:tuple, [{:literal, :replace_all_except}, {:wrap_list, :atom}]},
{:wrap_list, :atom}
]},
doc: """
The fields to overwrite in the case of an upsert. If not provided, all fields except for fields set by defaults will be overwritten.
"""
]
]
|> Spark.OptionsHelpers.merge_schemas(
@global_opts,
"Action Options"
)
|> Spark.OptionsHelpers.merge_schemas(
@create_update_opts,
"Create/Update Options"
)
@doc false
def opt_schema, do: @opt_schema
end