mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
Handle relationship filter on primary key (#1254)
Co-authored-by: Andreas Donig <git@innwiese.de>
This commit is contained in:
parent
7f2e7d3ec1
commit
23d504e151
1 changed files with 32 additions and 22 deletions
|
@ -2714,7 +2714,8 @@ defmodule Ash.Filter do
|
||||||
|> Map.update!(:relationship_path, fn path -> path ++ [rel.name] end)
|
|> Map.update!(:relationship_path, fn path -> path ++ [rel.name] end)
|
||||||
|> Map.put(:resource, rel.destination)
|
|> Map.put(:resource, rel.destination)
|
||||||
|
|
||||||
if is_list(nested_statement) || is_map(nested_statement) do
|
cond do
|
||||||
|
is_list(nested_statement) || is_map(nested_statement) ->
|
||||||
case parse_expression(nested_statement, context) do
|
case parse_expression(nested_statement, context) do
|
||||||
{:ok, nested_expression} ->
|
{:ok, nested_expression} ->
|
||||||
{:ok, BooleanExpression.optimized_new(:and, expression, nested_expression)}
|
{:ok, BooleanExpression.optimized_new(:and, expression, nested_expression)}
|
||||||
|
@ -2722,9 +2723,18 @@ defmodule Ash.Filter do
|
||||||
{:error, error} ->
|
{:error, error} ->
|
||||||
{:error, error}
|
{:error, error}
|
||||||
end
|
end
|
||||||
else
|
|
||||||
|
rel.type != :many_to_many && !Map.get(rel, :no_attributes) &&
|
||||||
|
[rel.source_attribute] == Ash.Resource.Info.primary_key(rel.destination) ->
|
||||||
|
with attr <- attribute(%{public?: true, resource: rel.source}, rel.source_attribute),
|
||||||
|
%Ash.Resource.Attribute{type: type, constraints: constraints} = attr,
|
||||||
|
{:ok, casted} <- Ash.Type.cast_input(type, nested_statement, constraints) do
|
||||||
|
add_expression_part({attr, casted}, %{context | resource: rel.source}, expression)
|
||||||
|
end
|
||||||
|
|
||||||
|
true ->
|
||||||
with [field] <- Ash.Resource.Info.primary_key(context.resource),
|
with [field] <- Ash.Resource.Info.primary_key(context.resource),
|
||||||
attribute <- attribute(context, field),
|
attribute when not is_nil(attribute) <- attribute(context, field),
|
||||||
{:ok, casted} <-
|
{:ok, casted} <-
|
||||||
Ash.Type.cast_input(attribute.type, nested_statement, attribute.constraints) do
|
Ash.Type.cast_input(attribute.type, nested_statement, attribute.constraints) do
|
||||||
add_expression_part({field, casted}, context, expression)
|
add_expression_part({field, casted}, context, expression)
|
||||||
|
|
Loading…
Reference in a new issue