alakasam
AEAsh Elixir
•Created by alakasam on 6/24/2023 in #support
Using Ecto preload to load relationships in one query
Hello! Loving using Ash so far. I'm trying to make a simple Reddit clone, and I have a structure basically like this:
- Post
- belongs to an author (user)
- belongs to a community
When I display a post, I need to fetch the author and the community (so I can link to both). Currently I'm doing this by just building a
load
into my action:
However, this does not do a join, but instead does two separate queries (one for the author
, one for the community
):
How do I modify this to fetch everything in a single query? When I get into fetching nested comments in a bit, having to fetch the users and the counts in separate queries feels like it would get slow. Is there a way I can use Ecto's preload
option in Ash?3 replies