-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
ping @jenssegers |
Is this a breaking change? |
No, just a fix. I updated the tests to force the error when filled. |
Will take a look tomorrow |
@@ -154,7 +154,7 @@ protected function getConstrainedRelatedIds($relations, $operator, $count) | |||
protected function getRelatedConstraintKey($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.
Add type for $relation
in doc block upper please
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.
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.
Done with that, also updated has()
to comply with Laravel signature Relation|string.
tests/RelationsTest.php
Outdated
@@ -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]); |
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.
What happens if we leave name user_id
?
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.
Well, if we leave 'user_id' then there is no way to check that HasOne / HasMany respects $localKey parameter.
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 will make a cleaner test, using a different Model to test this.
@stephandesouza merge actual master |
@Smolevich @jenssegers any chances to merge it now? |
This PR can have break changes, we need test on this case for example from #1902 |
HasOne / HasMany must respect $localKey parameter
Fixes a bunch of issues.
#1817 #1807 #1692 #1691 #1617 #1540 #1467
I thing there are more related