diff --git a/lib/ex_machina/ecto.ex b/lib/ex_machina/ecto.ex index 70d9d1c..b3563e6 100644 --- a/lib/ex_machina/ecto.ex +++ b/lib/ex_machina/ecto.ex @@ -50,11 +50,11 @@ defmodule ExMachina.Ecto do This is only for use with Ecto models. Will return a map with the fields and virtual fields, but without the Ecto - metadata and associations. + metadata, associations, and the primary key. ## Example - def factory(:user) do + def user_factory do %MyApp.User{name: "John Doe", admin: false} end @@ -71,6 +71,7 @@ defmodule ExMachina.Ecto do |> Map.from_struct |> Map.delete(:__meta__) |> Map.drop(struct.__schema__(:associations)) + |> Map.drop(struct.__schema__(:primary_key)) end defp drop_ecto_fields(record) do raise ArgumentError, "#{inspect record} is not an Ecto model. Use `build` instead." diff --git a/test/ex_machina/ecto_test.exs b/test/ex_machina/ecto_test.exs index f6d48dc..65f05e2 100644 --- a/test/ex_machina/ecto_test.exs +++ b/test/ex_machina/ecto_test.exs @@ -57,7 +57,6 @@ defmodule ExMachina.EctoTest do test "params_for/2 removes Ecto specific fields" do assert Factory.params_for(:user) == %{ - id: nil, name: "John Doe", admin: false }