-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement new config to specify return type of custom relations #1300
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, left a minor feedback and can you please also cover not just the 'many
' test but also 'morphTo'
? (or did I miss it?)
Oh, and please also add it to the README; otherwise it's hard to discover for others. |
Co-authored-by: Markus Podar <[email protected]>
I added a test for the morphTo case. I'm not sure where to put documentation on this feature. The config option |
If you can spare the time, this would be terrific! I believe that mentioning things in the README (aka our primary docs) definitely makes things easier to figure out for other developers. PS: you can ignore the failed tests, I've a separate PR for fixing this in #1351 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yissir, LGTM, thanks for your work!
ping @barryvdh
…yvdh#1300) * Implement new config to specify return type of custom relations * Apply suggestions from code review Co-authored-by: Markus Podar <[email protected]> * add test for morphed * fix test output * add info about how to add custom relationships * fix wording Co-authored-by: Markus Podar <[email protected]>
Summary
Custom Relation types can be added using the config
additional_relation_types
already, but in the backend the return types for those relations is determined by using a simple check determining if the class name hasMany
in it to decide the return type of the relation.This works for the built-in Laravel relations where they are named properly but packages like https://github.com/staudenmeir/eloquent-json-relations use a name such as
belongsToJson
to return a many relationship. This change allows a config option to specify the actual return type of the relation such as many or morphToType of change
Checklist
composer fix-style