Sorting on a field in a relation
I tried the solution from https://discordapp.com/channels/711271361523351632/1072944619169534063, but can't seem to get it to work. Am I missing something?
tweet.ex
item.ex
liveview file
Discord
Discord - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
15 Replies
That looks right to me, what is the error/stack trace you’re seeing?
No error. Just doesn't sort it in the expected order. I will keep looking. Thanks!
huh, that is strange. Would be good to look at the SQL logs to see what its doing wrong?
Okay will do
I realized my use case is different from the post referrenced above, so the aggregation
first
won't work. tweets
has many items
and the items need to be ordered by the value of its row_order
field. Feels like this is a common use case, but I can't seem to find the related documentation.
The current output looks like the following, but I'm trying to get the items to be listed in the ascending order. (ie. row_order 1, 3, 5, rather than 1, 5 ,3 )
you would load them with a query
load(stuff, items: Ash.Query.sort(Item, row_order: :asc))
Thanks!
This seems to work.
but not this. Is there. (the
load
part appears to be added to the load
setting defined in the action feed
) What's the right way to write it?
Either one should work actually…but try making it a single query
I.e
items: Ash.Query.sort(…) |> Ash.Query.load(…)
The top one actually works. It's the bottom one I'm trying to get to work.
Even if I change it to this, by removing :like_count ,
`
I still get this error
Try removing it from the list, sorry
Need to work on the accepted formats there
Like
items: query
But if I remove it from the list(but leave other attributes/calculations to load), sorting doesn't take effect even if it's defined in the action. Looks like
load
in Tweets.Tweet.get_by_id(user_id, load: ....)
overrides the build( load
inside the action.
Sorry, here is what I mean
how do I add attribute/calculation to it?
Is something like this allowed?
Ahh... okay. thanks!