udoschneider

udoschneider

Getting sorted relations from resource via code interface

All,

I’m currently struggling to sort relationships loaded from a resource.

E.g. a resource “Domain” has multiple “Controls”.

Getting a domain and preload the controls is easy and works just fine:

Domain.get_by_identifier!(identifier, load: :controls)

However I’m struggling with getting those controls as sorted list. My gut feeling is that this should be possible because the Api.load/3 function also accepts [atom() | {atom(), atom() | Keyword.t()}] as load_statement type. This would allow for something like

Domain.get_by_identifier!(identifier, load: [{:controls, [identifier: asc]}])

This doesn’t work though :frowning:

Any pointers?

CU,

Udo

Most Liked

zachdaniel

zachdaniel

Creator of Ash

This is done via passing a query as the value :smiley:

Domain.get_by_identifier!(identifier, load: [controls: Ash.Query.sort(Control, identifier: :asc)]_
zachdaniel

zachdaniel

Creator of Ash

For the most part, yes. Ultimately an action gets called on the destination resource that validates/authorizes whatever you’re doing. If you want to put it behind an action you can do it like this:

read :... do
  prepare fn query, _ -> 
    Ash.Query.load(....)
  end
end

Where Next?

Popular in Questions Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New

We're in Beta

About us Mission Statement