fekle
AEAsh Elixir
•Created by fekle on 4/6/2023 in #support
Conditional filters in read actions
Hi there, I'm back with another quesion that i couldnt find an answer to - sorry if i missed something.
I have a resource with a list of form submissions, where i have a read action to get all form submission of a specific form id, with the form_id as an argument. that works fine.
Now i also want to add the possibility to get all records submitted after a specific date, which also works this way:
filter expr(submission_time >= ^arg(:min_submission_time))
.
Now, the :min_submission_time
argument is optional - i want to be able to use the same action for getting both all as well as the filtered submissions. Is there a way to have a conditional in the action to only apply the :min_submission_time
filter if the argument is not nil? As far as I know the action code is evaluated at compile time, so i cant use a normal elixir if/else.
I am aware that i could just split this up into 2 different actions, but that would require duplicating things like the default sort order and filtering by form id.
Thanks!21 replies
AEAsh Elixir
•Created by fekle on 2/23/2023 in #support
Ash Relationships with existing Ecto Repos
Hi there,
I'm currently working on integrating Ash into my existing Phoenix/Ecto/Postgres app. So far Ash looks amazing and seems to be exactly what I'm looking for - the power and balance of ecto but without having to create basic utility functions over and over and over again 😉
Sorry if my question has already been answered, I couldn't find anything on GH, google, docs or Discord.
However I don't yet want to migrate all my existing Ecto (Phoenix Context) resources all at once, but go step by step.
Now, I added a new Repo, Registry and API with a new resource and that works fine. However now I want to add a :belongs_to in my new resource's :relationships - and that needs to be a user, so the resource belongs to a user.
Thing is, the User resource already exists as a normal Ecto schema that is used in my app, so ash tells me it can't find the resource. Is there some way to have a "compatibility" layer between an existing ecto schema and an ash resource?
Thanks!
27 replies