Skip to content

[Feature] Support polymorphic to-many relations #47

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

Merged
merged 5 commits into from
Mar 12, 2021

Conversation

lindyhopchris
Copy link
Contributor

Adds a MorphToMany relation field, that effectively wraps multiple relation fields, for example:

MorphToMany::make('media', [
    BelongsToMany::make('images'),
    BelongsToMany::make('videos'),
]),

This relatonship aggregates the results from each of its sub-relations, with the value returned in either the data member of its relationship field, or in a relationship endpoint.

The field is writeable as long as:

  1. every sub-relationship is writeable (implements FillableToMany); and
  2. each resource type that can be in the relationships maps to a single sub-relation.

Include paths also work, with the include paths only being applied to the sub-relations for which the include path is valid.

Closes #8

@lindyhopchris lindyhopchris merged commit eaccb9c into develop Mar 12, 2021
@lindyhopchris lindyhopchris deleted the feature/polymorphic-to-many branch March 12, 2021 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support polymorphic to-many relationships
1 participant