[5.4] Set connection while retrieving models #18769
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #17395 we moved the model's
create()
andforceCreate()
methods to theBuilder
to allow something likeUser::on('myCustomConnection')->create();
, before that creating a model on a different collection was a bit hacky.After that it was pretty obvious that
hydrate()
andfromQuery()
can be moved to the builder instance as well, since we won't have to pass that $connection argument and we just get it from the Builder instance, that's when 1ae29d9 was committed.However in that commit we removed the argument but forgot to pass the connection name from the Builder instance, leaving the connection as
null
when we retrieve a model.In this PR we simply set the connection using
$this->query->getConnection()->getName()
, just like we do increate()
andforceCreate()
.This will solve the failing test in #18760 without having to re-introduce the
$connection
argument to thehydrate()
method.