Skip to content

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.

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