Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for eagerly loading associations via the include param #15

Closed
NullVoxPopuli opened this issue Apr 13, 2016 · 3 comments
Closed
Assignees

Comments

@NullVoxPopuli
Copy link
Owner

Similar to ActiveModelSerializer's include option, but for eagerly loading relationships, rather than just rendering them.

For example, instead of having to write this:

    render json: Level.includes(
      :attendances => [
        :housing_request,
        :housing_provision,
        :orders,
        :package,
        :attendee
      ]).find(params[:id]), include: params[:include]

we want the ability to have whatever is in the include param eagerly load the relationships for us upon model resolution so that our controller actions can remain as

    render json: model, include: params[:include]
@NullVoxPopuli
Copy link
Owner Author

See: https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializer/include_tree.rb for converting the string to a hash.


  • Do we want to silently fail if an association is spelled wrong, and just output a warning to the log?
  • Should we call the AMS include_tree module directly, or copy it to this repo?
    • if we copy it to this repo, then we can do some validation / name fixing against the ActiveRecord relationships

@NullVoxPopuli
Copy link
Owner Author

@NullVoxPopuli
Copy link
Owner Author

Actually going to close this, thanks to the https://github.com/salsify/goldiloader gem :-)

Thanks @salsify!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant