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

Quick pass at custom primary key #47

Merged
merged 1 commit into from
Aug 16, 2017
Merged
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
9 changes: 5 additions & 4 deletions lib/ecto_mnesia/planner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ defmodule EctoMnesia.Planner do
@doc """
Deletes a record from a Mnesia database.
"""
def delete(_repo, %{schema: _schema, source: {_, table}, autogenerate_id: autogenerate_id}, filter, _opts) do
pk = get_pk!(filter, autogenerate_id)
def delete(_repo, %{schema: schema, source: {_, table}, autogenerate_id: _autogenerate_id}, filter, _opts) do
pk = get_pk!(filter, schema.__schema__(:primary_key))
case Table.delete(table, pk) do
{:ok, ^pk} -> {:ok, []}
{:error, reason} -> {:error, reason}
Expand All @@ -271,9 +271,9 @@ defmodule EctoMnesia.Planner do
@doc """
Updates record stored in a Mnesia database.
"""
def update(_repo, %{schema: schema, source: {_, table}, autogenerate_id: autogenerate_id},
def update(_repo, %{schema: schema, source: {_, table}, autogenerate_id: _autogenerate_id},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function takes too many parameters (arity is 6, max is 5).

params, filter, _autogen, _opts) do
pk = get_pk!(filter, autogenerate_id)
pk = get_pk!(filter, schema.__schema__(:primary_key))
context = Context.new(table, schema)
update = Update.from_keyword(schema, table, params, context)

Expand All @@ -285,6 +285,7 @@ defmodule EctoMnesia.Planner do

# Extract primary key value or raise an error
defp get_pk!(params, {pk_field, _pk_type}), do: get_pk!(params, pk_field)
defp get_pk!(params, [pk_field]), do: get_pk!(params, pk_field)
defp get_pk!(params, pk_field) do
case Keyword.fetch(params, pk_field) do
:error -> raise Ecto.NoPrimaryKeyValueError
Expand Down