simonedelmann / crud-kit

CRUD for Vapor 4. We all write CRUD (Create-Read-Update-Delete) routes all the time. The intention of this package is to reduce repeating code and to provide a fast start for an API.
MIT License
56 stars 8 forks source link

Eager loading for indexAll #3

Closed code28 closed 4 years ago

code28 commented 4 years ago

Nice work! I also just used a generic approach in one of my projects (but way less sophisticated), so I'll definitely consider using this in the future!

One thing is missing for my use case: Eager loading of children on indexAll. I know, it's maybe not that simple CRUD-style, but it's definitely useful to adjust the query.

Right now, I unfortunately don't have the time to study your code and make a PR, maybe you can find a solution for this easily. Otherwise I'll look into making a PR when I get some spare time. :)

simonedelmann commented 4 years ago

Hey, thanks for your feedback! I think it would be very difficult to include eager loaded children into a parent indexAll Route as the parent controller does not know about the child model. But it would be possible to add an extra route for parent with eager loaded children. Assuming Todo -> Tags relationship:

/todos     // with eager loading not possible/very difficult
/todos/with-tags       // easy to implement

But I am not happy with the syntax. Do you have a suggestion for with-tags?

simonedelmann commented 4 years ago

After discussion on Discord we decided not to add an eager-loading route but to provide an (currently undocumented) option to customize the CRUDController to add eager loading.