Skip to content

HasOne / HasMany must respect $localKey parameter #1837

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 2 commits into from
Jan 30, 2020
Merged

HasOne / HasMany must respect $localKey parameter #1837

merged 2 commits into from
Jan 30, 2020

Conversation

stephandesouza
Copy link
Contributor

Fixes a bunch of issues.

#1817 #1807 #1692 #1691 #1617 #1540 #1467

I thing there are more related

@stephandesouza
Copy link
Contributor Author

ping @jenssegers

@jenssegers
Copy link
Contributor

Is this a breaking change?

@stephandesouza
Copy link
Contributor Author

No, just a fix. I updated the tests to force the error when filled.

@stephandesouza
Copy link
Contributor Author

@jenssegers ?

@stephandesouza
Copy link
Contributor Author

Will take a look tomorrow

@@ -154,7 +154,7 @@ protected function getConstrainedRelatedIds($relations, $operator, $count)
protected function getRelatedConstraintKey($relation)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add type for $relation in doc block upper please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with that, also updated has() to comply with Laravel signature Relation|string.

@@ -61,24 +61,24 @@ public function testBelongsTo(): void
public function testHasOne(): void
{
$user = User::create(['name' => 'John Doe']);
Role::create(['type' => 'admin', 'user_id' => $user->_id]);
Role::create(['type' => 'admin', 'roleuser_id' => $user->_id]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we leave name user_id?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if we leave 'user_id' then there is no way to check that HasOne / HasMany respects $localKey parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make a cleaner test, using a different Model to test this.

@divine divine mentioned this pull request Jan 25, 2020
@Smolevich
Copy link
Contributor

@stephandesouza merge actual master

@divine
Copy link
Contributor

divine commented Jan 30, 2020

@Smolevich @jenssegers any chances to merge it now?

@Smolevich Smolevich merged commit 9ebcc5a into mongodb:master Jan 30, 2020
@Smolevich
Copy link
Contributor

This PR can have break changes, we need test on this case for example from #1902

Smolevich added a commit to Smolevich/demo-mongo-application that referenced this pull request Jan 30, 2020
@Smolevich Smolevich added the bug label Jan 30, 2020
@stephandesouza stephandesouza deleted the fix-hasmany branch March 11, 2020 14:47
mnphpexpert added a commit to mnphpexpert/laravel-mongodb that referenced this pull request Sep 2, 2024
HasOne / HasMany must respect $localKey parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The key is not stored on HasMany relation Relationships with non-primary keys
4 participants