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

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement