Skip to content

[5.4] Some refactoring on Eloquent builder#18775

Merged
taylorotwell merged 1 commit into
laravel:5.4from
themsaid:refactor/eloquent/builder
Apr 11, 2017
Merged

[5.4] Some refactoring on Eloquent builder#18775
taylorotwell merged 1 commit into
laravel:5.4from
themsaid:refactor/eloquent/builder

Conversation

@themsaid

Copy link
Copy Markdown
Member

Extracted a new method that'll create a new model instance and set the connection to the same connection of the Builder instance:

public function newModelInstance($attributes = [])
{
    return $this->model->newInstance($attributes)->setConnection(
        $this->query->getConnection()->getName()
    );
}

Refactored the areas where this logic used to happen to call the method instead.

  • some minor docblock fixes.

@taylorotwell taylorotwell merged commit 7b3bf0b into laravel:5.4 Apr 11, 2017
@taylorotwell

Copy link
Copy Markdown
Member

Thanks

@gabrielkoerich

gabrielkoerich commented Jun 22, 2017

Copy link
Copy Markdown
Contributor

@themsaid This commit introduced a bug in my tests, if I create a model just using new Model() and save(), the connection is null, so all my comparisons using $model->is(...) doens't work anymore. Maybe we should use this new method in save() too? I don't know.

@themsaid

Copy link
Copy Markdown
Member Author

@gabrielkoerich I don't think this commit made a change to the code, we just extracted part of the code in a method.

@gabrielkoerich

gabrielkoerich commented Jun 22, 2017

Copy link
Copy Markdown
Contributor

@themsaid Yeap, that's weird. It was something between 5.4.18 and 5.4.19 (v5.4.18...v5.4.19), and the only commit that changed something with connections was this one... Do you know what else could it be? Thanks.

@gabrielkoerich

Copy link
Copy Markdown
Contributor

@themsaid I end up calling fresh() after creating the model and it's working.

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