mathieuprog / polymorphic_embed

Polymorphic embeds in Ecto
Apache License 2.0
325 stars 63 forks source link

(KeyError) key :array? not found in v5 #111

Closed woylie closed 4 weeks ago

woylie commented 4 weeks ago

After upgrading from 4.1.1 to 5.0.0, I'm getting this compile-time error:

** (KeyError) key :array? not found in: [
  retain_unlisted_types_on_load: [],
  nilify_unlisted_types_on_load: [],
  type_field_name: :__type__,
  types: [
    my_type_a: MyApp.MyTypeA,
    my_type_b: MyApp.MyTypeB
  ],
  on_type_not_found: :raise,
  on_replace: :update,
  field: :data,
  schema: MyApp.MySchema
]
    (elixir 1.17.2) lib/keyword.ex:602: Keyword.fetch!/2
    (polymorphic_embed 5.0.0) lib/polymorphic_embed.ex:121: PolymorphicEmbed.init/1
    (ecto 3.12.1) lib/ecto/parameterized_type.ex:196: Ecto.ParameterizedType.init/2
    (ecto 3.12.1) lib/ecto/schema.ex:2058: Ecto.Schema.__field__/4
    lib/my_app/my_schema.ex:24: (module)

my_schema.ex:24 is:

  embedded_schema do
    field :data, PolymorphicEmbed,
      types: [
        my_type_a: MyApp.MyTypeA,
        my_type_b: MyApp.MyTypeB
      ],
      on_type_not_found: :raise,
      on_replace: :update
  end
mathieuprog commented 4 weeks ago

Hello, interesting that you are using field instead of the macros polymorphic_embeds_one and polymorphic_embeds_many as documented.

Any reason?

woylie commented 4 weeks ago

Huh, I didn't notice. I don't know why it wasn't using polymorphic_embeds_one. I changed it and everything works fine. Thank you for the quick answer.