Modifying results after reading
Hi, 👋 I need to manipulate the data returned from a database query. I found out how to do my own read based on Ash.Resource.ManualRead, but how can I call the default logic to apply my changes afterwards? Or is there some kind of after_read hook where I could do so? I would appreciate som pointers… 😇
6 Replies
Hello! You can use a “preparation” and an after action hook to do what you want to do. Have you used query preparations before?
No, didn’t use it before, Looking into the docs… 📚
You’re looking at something like:
That can go in an individual action
Or in the global preparations block to run on all reads
Ah, got it! I want to integrate it as transparent as possible with the AshJsonApi layer. Thanks for the pointer! 👏
Waaaay better than my approach. Thank you so much!
Maybe you could change the title to something like "Modify results after reading from database"? My approach using Ash.Resource.ManualRead was a blind end…
👍👍 will do!
Please add the resolved tag and close the post if it’s been resolved 😀😀
Minor nitpick but could you please fix the title spelling @Zach Daniel since these are more or permanent posts for searching ?