diff --git a/lib/polymorphic_embed/options_validator.ex b/lib/polymorphic_embed/options_validator.ex index 806433e..a787865 100644 --- a/lib/polymorphic_embed/options_validator.ex +++ b/lib/polymorphic_embed/options_validator.ex @@ -18,14 +18,6 @@ defmodule PolymorphicEmbed.OptionsValidator do @valid_on_type_not_found_options [:raise, :changeset_error, :nilify, :ignore] def validate!(options) do - keys = Keyword.keys(options) - key_count = keys |> Enum.count() - unique_key_count = Enum.uniq(keys) |> Enum.count() - - if key_count != unique_key_count do - raise "Duplicate keys found in options for polymorphic embed." - end - unless Keyword.fetch!(options, :on_replace) in @valid_on_replace_options do raise( "`:on_replace` must be set to `:update` for a single polymorphic embed or `:delete` for a list of polymorphic embeds." @@ -60,6 +52,14 @@ defmodule PolymorphicEmbed.OptionsValidator do raise "`:retain_unlisted_types_on_load` must be a list of types as atoms." end + keys = Keyword.keys(options) + key_count = keys |> Enum.count() + unique_key_count = Enum.uniq(keys) |> Enum.count() + + if key_count != unique_key_count do + raise "Duplicate keys found in options for polymorphic embed." + end + unknown_options = Keyword.drop(options, @known_options_names) if length(unknown_options) > 0 do