How to define a read method for preloading associations inside a resource?
Apologies for the noob question, but I couldn't find it in the docs. Let's say I have an author resource that
has_many
posts. How do I use the read DSL to get an author by its ID and preload its associated posts?3 Replies
How are you reading the resource currently? I.e if you are running a query, you could do something like
Or you could load posts on some records you received after the fact
Or you could do it in the action and then they would be loaded every time you read them
That last approach might be a bad idea though
Wow, I didn't expect to get answers immediately. I love the first approach and I'm going to use that. Thanks so much!
Happy to help 🙂