fekle
fekle
AEAsh Elixir
Created by fekle on 4/6/2023 in #support
Conditional filters in read actions
great, thanks again for your help!
21 replies
AEAsh Elixir
Created by fekle on 4/6/2023 in #support
Conditional filters in read actions
cleaner like this, seems to work - thanks!! 🙂
filter expr(
form_id == ^arg(:form_id) and
if not is_nil(^arg(:min_submission_time)) do
submission_time >= ^arg(:min_submission_time)
else
true
end
)
filter expr(
form_id == ^arg(:form_id) and
if not is_nil(^arg(:min_submission_time)) do
submission_time >= ^arg(:min_submission_time)
else
true
end
)
21 replies
AEAsh Elixir
Created by fekle on 4/6/2023 in #support
Conditional filters in read actions
so you mean like this?
filter expr(
expr(form_id == ^arg(:form_id)) and
expr(
if not is_nil(^arg(:min_submission_time)) do
submission_time >= ^arg(:min_submission_time)
else
true
end
)
)
filter expr(
expr(form_id == ^arg(:form_id)) and
expr(
if not is_nil(^arg(:min_submission_time)) do
submission_time >= ^arg(:min_submission_time)
else
true
end
)
)
21 replies
AEAsh Elixir
Created by fekle on 4/6/2023 in #support
Conditional filters in read actions
Well but when i think of it, if there are multiple filters then its unclear if they are AND or OR 🙂 so there would need to be a new syntax
21 replies
AEAsh Elixir
Created by fekle on 4/6/2023 in #support
Conditional filters in read actions
I can combine both filters like this - is that the "idiomatic" syntax for this?
filter [
expr(form_id == ^arg(:form_id)),
expr(
if not is_nil(^arg(:min_submission_time)) do
submission_time >= ^arg(:min_submission_time)
else
true
end
)
]
filter [
expr(form_id == ^arg(:form_id)),
expr(
if not is_nil(^arg(:min_submission_time)) do
submission_time >= ^arg(:min_submission_time)
else
true
end
)
]
21 replies
AEAsh Elixir
Created by fekle on 4/6/2023 in #support
Conditional filters in read actions
OK, my bad it always ignores the first filter - seems like i can only have one filter.
21 replies
AEAsh Elixir
Created by fekle on 4/6/2023 in #support
Conditional filters in read actions
thats how it looks now:
read :get_records do
argument :form_id, :integer do
allow_nil? false
end

argument :min_submission_time, :utc_datetime do
allow_nil? true
end

prepare build(sort: [submission_id: :desc])

filter expr(form_id == ^arg(:form_id))

filter expr(
if not is_nil(^arg(:min_submission_time)) do
submission_time >= ^arg(:min_submission_time)
else
true
end
)
end
read :get_records do
argument :form_id, :integer do
allow_nil? false
end

argument :min_submission_time, :utc_datetime do
allow_nil? true
end

prepare build(sort: [submission_id: :desc])

filter expr(form_id == ^arg(:form_id))

filter expr(
if not is_nil(^arg(:min_submission_time)) do
submission_time >= ^arg(:min_submission_time)
else
true
end
)
end
21 replies
AEAsh Elixir
Created by fekle on 4/6/2023 in #support
Conditional filters in read actions
- if I keep the else true in it, then it seems to ignore other filters in the action - if i remove the else true then i always get 0 results
21 replies
AEAsh Elixir
Created by fekle on 4/6/2023 in #support
Conditional filters in read actions
Thanks! I tried the second solution but found the following
21 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
thank you very much for your help, that cleared up things for me! 🙂
27 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
In the meanwhile i'm thinking that maybe using an argument and handling the value in my actions is the better way do do this. there i could use the argument user_id for my validation and then always setting the attribute based on that argument
27 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
yes, its a bit of an edge case. the item in the form belongs to a user, and has a number field - but the max value of the number field depends on a value in the user profile, so i need it for validation
27 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
yes some kind of "unmodifyable values" that are always overwritten in the params. Maybe I'll have a look at opening a PR for that 🙂
27 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
before_submit unfortunately only works with submit and not validate, i need the attribute for validation
27 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
I understand, yeah thats the reason I dont like using hidden fields etc.
27 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
Ah, i saw that before but that didnt work, as i want to set an attribute and not an argument. But using Ash.Changeset.change_attribute/3 in this works.
27 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
One more quick question that I couldnt find the answer for: When using AshPhoenix.Form, is it possible to add values that are always applied when validating or submitting the form? For example a user id? I know that i can do this with a hidden input or by modifying the params before validating/submitting, but is there a more idiomatic way? The "params" option gets lost after the first validate.
27 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
thanks a lot! I will do that 🙂
27 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
so that means i could have a new ash resource for my users which uses the same postgres table as my existing ecto schema, and keep using my ecto schema for existing functions? sounds like a good compromise
27 replies
AEAsh Elixir
Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
I understand, thanks for your swift reply! So i'll just use a normal uuid field for now and manage the relationship manually, and when I migrate my user resource i should be able to reuse the existing uuid field.
27 replies