File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -372,7 +372,7 @@ defmodule PolymorphicEmbed do
372372 type_field_name: type_field_name
373373 } = field_opts
374374
375- list_data_for_field = Map . fetch! ( changeset . data , field )
375+ list_data_for_field = Map . fetch! ( changeset . data , field ) || [ ]
376376
377377 embeds =
378378 Enum . map ( list_params , fn params ->
Original file line number Diff line number Diff line change @@ -1669,6 +1669,7 @@ defmodule PolymorphicEmbedTest do
16691669 address: "address"
16701670 }
16711671 ] ,
1672+ contexts2: nil ,
16721673 contexts3: [
16731674 % {
16741675 __type__: "device" ,
@@ -1784,6 +1785,27 @@ defmodule PolymorphicEmbedTest do
17841785 ]
17851786 }
17861787
1788+ assert { :ok , _ } =
1789+ reminder
1790+ |> reminder_module . changeset ( attrs )
1791+ |> Repo . update ( )
1792+
1793+ # Make sure it works for embeds with nil entries
1794+ attrs = % {
1795+ contexts2: [
1796+ % {
1797+ __type__: "device" ,
1798+ ref: "12345" ,
1799+ type: "cellphone"
1800+ } ,
1801+ % {
1802+ __type__: "device" ,
1803+ ref: "56789" ,
1804+ type: "laptop"
1805+ }
1806+ ]
1807+ }
1808+
17871809 assert { :ok , _ } =
17881810 reminder
17891811 |> reminder_module . changeset ( attrs )
You can’t perform that action at this time.
0 commit comments