[Proposal] Relationship Eager Loading for Fractal Includes
xwiz opened this issue · comments
Q | A |
---|---|
Bug? | no |
New Feature? | yes |
Framework | Laravel |
Framework version | 6.x |
Package version | 2.4.x |
PHP version | 7.3 |
Actual Behaviour
Currently, Dingo tries to eagerload model based on the include keys in transformer, and uses the value as the resource key.
Expected Behaviour
It should be the other way round. The array key should be the resource key and the value should be used as the relationship name. This way, it won't affect the resource keys in the include
query string.
Explanation
If would like to have something like this:
public $availableIncludes = ['billing_type' => 'billingType'];
instead of:
public $availableIncludes = ['billingType' => 'billing_type'];
in order to use a query string like myapiurl?include=billing_type
Comments
Is there a reason why it is implemented in the current way? Because I assume this is how it should have been thought about in the first place.
Note: After further testing, it seems this happens only with defaultIncludes? I'm confused, has this been implemented or is this manifestation part of fractal?
I have resolved this by using a CustomSerializer. It seems the issue is from Fractal.
If you have fixed it, I encourage you to do a PR into the fractal serializer project for the benefit of other users.