-
Notifications
You must be signed in to change notification settings - Fork 288
feat: support for polymorphic relations #204
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
feat: support for polymorphic relations #204
Conversation
Thanks. This makes much more sense now. In seeing the draft, I propose the following syntax: models:
Post:
name: string:400
relationships:
morphMany: Image
User:
name: string:400
relationships:
morphMany: Image
Image:
url: string:400
relationships:
morphTo: Imageable This would overcome the |
@jasonmccreary Thanks, tonight I will refactor this pull request. |
@jasonmccreary I've updated the pull request. There is one thing that is missing thought, the generated migration for the |
@Pr3d4dor, yes. I would think for whatever models have the |
@jasonmccreary I've updated the pull request adding the support for polymorphic relations in migrations. There is one adjustment that needs to be made: The migration for the table that contains |
Looks pretty good. I have some small changes I'll make. Why does it need to come first? |
Sorry 😂, I confused myself looking in the Laravel Documentation. It doesn't need to come first. |
Hello, I think that it will be very helpful if you could update the official documentation to include polymorphic relationships syntax. |
@mahfoudfx, totally agree. A bit busy at the moment. Would you be willing to submit a PR to the docs repo to help get this started? |
@jasonmccreary , I've submitted a PR. I hope it's correct or require a little changes. Also, I tried also to write something regarding morphToMany and hasManyThrough, but I found nothing and I'm not sure if blueprint handle them. |
This pull request adds support for polymorphic relations.
This approach can be optimized.
The problem is that we need to add the
morphTo
method to the related model on themorphOne
andmorphMany
.Example, given the following definition:
We need to add
morphMany
toPost
andUser
models, but we also need to add themorphTo
method to theImage
model. Using this approach we solve the need to addmorphTo: null
to the definition, like the #202 pull request.I think that, adding the
morphTo
relationship before the output, to the referenced model, is a "cheat". But I could not come up with a cleaner way to do this.Supercedes #202
Closes #199