Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Feature] Add MorphToMany support #2670

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
GromNaN merged 81 commits into mongodb:4.1 from hans-thomas:2640-morph-to-many
Nov 22, 2023
Merged

Conversation

@hans-thomas
Copy link
Contributor

@hans-thomas hans-thomas commented Nov 7, 2023
edited
Loading

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 models
  • detaching action
  • finally syncing action
  • There is a problem with loading relation using load method

It has to be done by tomorrow.

ithuis reacted with thumbs up emoji
ithuis and others added 30 commits October 12, 2023 17:09
attach MorphToMany working
detaching works
sync working
cleanup
# Conflicts:
#	tests/RelationsTest.php
Comment on lines +36 to +40
/** @inheritdoc */
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
{
return $query;
}
Copy link
Contributor Author

@hans-thomas hans-thomas Nov 16, 2023

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.

Copy link
Contributor Author

@hans-thomas hans-thomas Nov 18, 2023

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;
Comment on lines -117 to +125
$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))
};
Copy link
Contributor Author

@hans-thomas hans-thomas Nov 18, 2023

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.

GromNaN reacted with thumbs up emoji
Copy link
Member

@alcaeus alcaeus left a 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! ❤️

hans-thomas reacted with heart emoji ithuis reacted with rocket emoji
Copy link
Contributor Author

@alcaeus My pleasure❤️

Co-authored-by: Andreas Braun <alcaeus@users.noreply.github.com>
Copy link
Member

@GromNaN GromNaN left a 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.

hans-thomas reacted with heart emoji

if ($this->getInverse()) {
// Attach the new ids to the parent model.
$this->parent->push($this->table, [
Copy link
Member

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.

hans-thomas reacted with heart emoji
@GromNaN GromNaN merged commit 82ddb83 into mongodb:4.1 Nov 22, 2023
Copy link
Member

GromNaN commented Nov 22, 2023

Thank you so much @hans-thomas

ithuis reacted with hooray emoji hans-thomas reacted with heart emoji

@hans-thomas hans-thomas deleted the 2640-morph-to-many branch November 22, 2023 11:38
Copy link
Contributor Author

@GromNaN I'm glad I could help❤️

Treggats pushed a commit to Treggats/laravel-mongodb that referenced this pull request Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@alcaeus alcaeus alcaeus approved these changes

@GromNaN GromNaN GromNaN approved these changes

@jmikola jmikola Awaiting requested review from jmikola

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /