Skip to content

Commit

Permalink
fix: Action Relationship Params are non-empty (#41)
Browse files Browse the repository at this point in the history
An action always includes params for the relationship status.  This
commit fixes a 500 error that occurred by using unguarded params for the
index `filter_by_relationship` function that returned an `{:error,
:not_found}` tuple.

Also adds some better callbacks for the action to provide some type
enforcement.
  • Loading branch information
staylorwr committed Nov 17, 2020
1 parent 60ce232 commit 592c220
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/ex_teal/action.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ defmodule ExTeal.Action do

@callback commit(Plug.Conn.t(), [ExTeal.Field.t()], Ecto.Query.t()) :: action_responses()

@doc """
Override the default title for the action
"""
@callback title() :: String.t()

@doc """
Override the default key for the action
"""
@callback key() :: String.t()

defmacro __using__(_) do
quote do
@behaviour ExTeal.Action
Expand Down
3 changes: 2 additions & 1 deletion lib/ex_teal/resource/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ defmodule ExTeal.Resource.Index do
"via_resource_id" => resource_id,
"via_relationship" => rel_name
}
) do
)
when resource_name != "" and resource_id != "" and rel_name != "" do
with {:ok, resource} <- ExTeal.resource_for(resource_name),
{:ok, relationship} <- schema_assoc_for(resource, rel_name) do
from(query, where: ^[{relationship.related_key, resource_id}])
Expand Down

0 comments on commit 592c220

Please sign in to comment.