feat: add source option to attributes

This commit is contained in:
Zach Daniel 2022-02-14 11:38:45 -05:00
parent c41761ef62
commit 15bdae0d99
4 changed files with 18 additions and 3 deletions

View file

@ -109,6 +109,7 @@ locals_without_parens = [
sensitive?: 1,
soft?: 1,
sort: 1,
source: 1,
source_field: 1,
source_field_on_join_table: 1,
strategy: 1,

View file

@ -13,6 +13,7 @@ defmodule Ash.Resource.Attribute do
:default,
:update_default,
:description,
:source,
sensitive?: false,
filterable?: true,
constraints: []
@ -52,6 +53,12 @@ defmodule Ash.Resource.Attribute do
doc:
"Whether or not the attribute value contains sensitive information, like PII. If so, it will be redacted while inspecting data."
],
source: [
type: :atom,
doc: """
If the field should be mapped to a different name in the data layer.
"""
],
always_select?: [
type: :boolean,
default: false,

View file

@ -33,7 +33,8 @@ defmodule Ash.Schema do
constraint_opts,
primary_key: attribute.primary_key?,
read_after_writes: read_after_writes?,
redact: attribute.sensitive?
redact: attribute.sensitive?,
source: attribute.source
)
)
end
@ -120,7 +121,8 @@ defmodule Ash.Schema do
constraint_opts,
primary_key: attribute.primary_key?,
read_after_writes: read_after_writes?,
redact: attribute.sensitive?
redact: attribute.sensitive?,
source: attribute.source
)
)
end

View file

@ -25,7 +25,12 @@ defmodule Ash.Resource.Transformers.SetTypes do
Transformer.replace_entity(
dsl_state,
[:attributes],
%{attribute | type: type, constraints: constraints},
%{
attribute
| type: type,
constraints: constraints,
source: attribute.source || attribute.name
},
fn replacing ->
replacing.name == attribute.name
end