diff --git a/lib/ex_machina/ecto.ex b/lib/ex_machina/ecto.ex index 7a1bded..0efb9e5 100644 --- a/lib/ex_machina/ecto.ex +++ b/lib/ex_machina/ecto.ex @@ -276,9 +276,11 @@ defmodule ExMachina.Ecto do association = struct.__schema__(:association, association_name) with %{__struct__: Ecto.Association.BelongsTo} <- association, - %{__meta__: %{__struct__: Ecto.Schema.Metadata, state: :loaded}} = belongs_to <- - Map.get(record, association_name) do + belongs_to <- Map.get(record, association_name), + %{__meta__: %{__struct__: Ecto.Schema.Metadata, state: :loaded}} <- belongs_to do set_belongs_to_primary_key(record, belongs_to, association) + else + _ -> record end end) end diff --git a/lib/ex_machina/sequence.ex b/lib/ex_machina/sequence.ex index bbbbeb8..10a3c17 100644 --- a/lib/ex_machina/sequence.ex +++ b/lib/ex_machina/sequence.ex @@ -77,14 +77,13 @@ defmodule ExMachina.Sequence do ExMachina.Sequence.next("joe") # "joe0" """ - @spec reset(list()) :: :ok + @spec reset(any()) :: :ok def reset(sequence_names) when is_list(sequence_names) do Agent.update(__MODULE__, fn sequences -> Enum.reduce(sequence_names, sequences, &Map.put(&2, &1, 0)) end) end - @spec reset(any()) :: :ok def reset(sequence_name) do Agent.update(__MODULE__, fn sequences -> Map.put(sequences, sequence_name, 0)