-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[Feature] Add MorphToMany support #2670
Conversation
attach MorphToMany working detaching works sync working cleanup
# Conflicts: # tests/RelationsTest.php
/** @inheritdoc */ | ||
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*']) | ||
{ | ||
return $query; | ||
} |
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.
I think the parent method is fine and we don't need to override this. I will write test for this too.
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.
This one is related to HybridRelations
and never called in my tests.
We don't need this method anymore;
This reverts commit 5d229eb.
$relations = $hasQuery->pluck($this->getHasCompareKey($relation)); | ||
$relations = match (true) { | ||
$relation instanceof MorphToMany => $relation->getInverse() ? | ||
$this->handleMorphedByMany($hasQuery, $relation) : | ||
$this->handleMorphToMany($hasQuery, $relation), | ||
default => $hasQuery->pluck($this->getHasCompareKey($relation)) | ||
}; |
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.
I added a match
expression to handle the MorphToMany
relations has
query.
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.
Just a minor comment. Thanks for working on this @hans-thomas, and I really appreciate the amount of comments you added to the code! ❤️
@alcaeus My pleasure❤️ |
Co-authored-by: Andreas Braun <alcaeus@users.noreply.github.com>
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. A last question about the commented code and minor CS fixes.
|
||
if ($this->getInverse()) { | ||
// Attach the new ids to the parent model. | ||
$this->parent->push($this->table, [ |
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.
Great 👍🏻 It seems that you have tested this case carefully.
Co-authored-by: Jérôme Tamarelle <jerome@tamarelle.net>
Co-authored-by: Jérôme Tamarelle <jerome@tamarelle.net>
Thank you so much @hans-thomas |
@GromNaN I'm glad I could help❤️ |
Hi,
I continued #2640 PR, thanks to @ithuis. I fixed the relationship and its inverse way,
but it still needs more tests for
attaching
a collection of modelsdetaching
actionsyncing
actionload
methodIt has to be done by tomorrow.