Allow override of eager load on transformer #1036
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have hunted through the docs and source code for this and seen some things that make me think this is available, however I was unable to find anyway to do it without a file change.
The idea of this is simple, if you have a collection that you do not want to eager load to disable it for just that transformer (or just that model).
The use case for me is that I have some polymorphic relations that need to get a related item from the related model. So if I use the transformer normally It will error as it tries to eager load when it needs to load an extra sub module. I can think of other ways around this (at the cost of verbosity) but I do see the use for being able to disable eager loading in some cases.
The way to use this is to just add a function in the model you are using for the transform and make a function called
apiEagerLoad
and return true or false. It will automatically check and use that function to override.There is likely better ways to do this. I for one don't like targeting the first result to get to the model, probably adding extra parameters to collection/item that can trigger the
disableEagerLoad
function in the manager would be better. However I am not confident in my understanding of this package so I decided on the simplest solution to get my point across.