Open stanleygtrillion opened 4 days ago
I think you'll want to use the :in
operator here and pass the list of UUIDs you want to filter on as filter value.
:in
will not work in this scenario, it will throw this error:
%{
"filters" => %{
"0" => %{
"field" => "new_uuid",
"op" => "in",
"value" => ["8ff7ccfd-b896-41e4-97f6-4b4516f57f62"]
}
}
}
Invalid Flop: #Ecto.Changeset<action: :replace, changes: %{first: 25, filters: [#Ecto.Changeset<action: :insert, changes: %{value: [\"8ff7ccfd-b896-41e4-97f6-4b4516f57f62\"], op: :in, field: :new_uuid}, errors: [op: {\"is invalid\", [allowed_operators: [:=~, :like, :not_like, :like_and, :like_or, :ilike, :not_ilike, :ilike_and, :ilike_or, :empty, :not_empty]]}], data: #Flop.Filter<>, valid?: false>], order_by: [:inserted_at], order_directions: [:desc]}, errors: [], data: #Flop<>, valid?: false>
this is because :in
is not part of the allowed_operators for compound fields
@woylie mind taking a look at this PR: https://github.com/woylie/flop/pull/518
i have added test cases for the new proposed :or
operator to facilitate this operation
do let me know how i can improve it.
thank you
currently compound_fields automatically hardcode type to :string but in the case of compound_fields of 2 uuid fields, performing filter to this compound_field will fail
e.g.
with op
like_or
will generateuuid1 like $1 OR uuid2 like $1
this will fail because uuid operation withlike
throw error at postgres e.g:select * from my_table where id like '<uuid value>';
is it possible to defined the ecto_type on compound_fields so on building the like_or operation it will generate
uuid1 = $1 OR uuid2 = $2