Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't return id field in params_for #123

Merged
merged 1 commit into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/ex_machina/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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."
Expand Down
1 change: 0 additions & 1 deletion test/ex_machina/ecto_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down