File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -262,7 +262,10 @@ defmodule Spark.Builder.Entity do
262262 if Keyword . has_key? ( schema , :* ) do
263263 :ok
264264 else
265- schema_keys = Keyword . keys ( schema )
265+ schema_keys =
266+ Enum . map ( schema , fn { key , opts } ->
267+ opts [ :as ] || key
268+ end )
266269
267270 auto_keys =
268271 case auto do
Original file line number Diff line number Diff line change @@ -280,6 +280,27 @@ defmodule Spark.Builder.EntityTest do
280280 |> Entity . build ( )
281281 end
282282
283+ test "allows identifier referencing :as alias" do
284+ { :ok , _entity } =
285+ Entity . new ( :attr , TestTarget ,
286+ schema: [ source_field: [ type: :atom , as: :source ] ] ,
287+ identifier: :source
288+ )
289+ |> Entity . build ( )
290+ end
291+
292+ test "rejects identifier referencing original key when :as alias exists" do
293+ result =
294+ Entity . new ( :attr , TestTarget ,
295+ schema: [ source_field: [ type: :atom , as: :source ] ] ,
296+ identifier: :source_field
297+ )
298+ |> Entity . build ( )
299+
300+ assert { :error , message } = result
301+ assert message =~ "identifier references undefined"
302+ end
303+
283304 test "validates args with optional format" do
284305 { :ok , _entity } =
285306 Entity . new ( :attr , TestTarget ,
You can’t perform that action at this time.
0 commit comments