Skip to content
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

[5.4] Fix BelongsTo not accepting id == 0 in foreign relations #17668

Merged
merged 1 commit into from
Jan 30, 2017

Conversation

antonioribeiro
Copy link
Contributor

BelongsTo is not able to eager load relations when the id == 0.

This is a bug introduced in 5.4.

The code in 5.3 only checked for nulls:

    foreach ($models as $model) {
        if (! is_null($value = $model->{$this->foreignKey})) {
            $keys[] = $value;
        }
    }

In 5.4, as it is using array_filter(), it's now also excluding '', false and 0.

@@ -143,6 +151,11 @@ class AnotherEloquentBelongsToModelStub extends \Illuminate\Database\Eloquent\Mo
public $foreign_key = 'foreign.value.two';
}

class EloquentBelongsToModelStubWithIdZero extends \Illuminate\Database\Eloquent\Model
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be
EloquentBelongsToModelStubWithZeroId?

@taylorotwell
Copy link
Member

Might as well just change it back to a loop honestly. This is harder to read.

@antonioribeiro
Copy link
Contributor Author

@taylorotwell, changed it back to a loop.
@fernandobandeira renamed that method.

@taylorotwell taylorotwell merged commit d939078 into laravel:5.4 Jan 30, 2017
@taylorotwell
Copy link
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants