diff --git a/.formatter.exs b/.formatter.exs index adc03cc8..f722686a 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -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, diff --git a/lib/ash/resource/attribute.ex b/lib/ash/resource/attribute.ex index 692515cf..6b670390 100644 --- a/lib/ash/resource/attribute.ex +++ b/lib/ash/resource/attribute.ex @@ -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, diff --git a/lib/ash/resource/schema.ex b/lib/ash/resource/schema.ex index 7d3f8f0d..a679bee8 100644 --- a/lib/ash/resource/schema.ex +++ b/lib/ash/resource/schema.ex @@ -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 diff --git a/lib/ash/resource/transformers/set_types.ex b/lib/ash/resource/transformers/set_types.ex index 3942c40c..190855cb 100644 --- a/lib/ash/resource/transformers/set_types.ex +++ b/lib/ash/resource/transformers/set_types.ex @@ -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