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
fix(HasAttributes) no cast when use expressions #6375
base: master
Are you sure you want to change the base?
Conversation
补一个单测? |
if ($value instanceof Expression) { | ||
return $value; | ||
} | ||
|
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.
测试过么?这么改可以?
Laravel 是这么处理的么?
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.
测试过了
Laravel也有这个问题,还没解决
已补 |
模型方法不能支持这种写法 后期会有各种问题
|
你可以先给 Laravel 提交代码,如果 Laravel 合并了代码,我们再来讨论是否要合并吧 |
可以举个可能出现问题的例子吗? |
现在的情况是模型都不支持这种写法。 一旦这里支持了,就需要所有的地方都支持,像你现在这种写法,还需要强制从数据库里 refresh 到最新结果,是不太合适的。 你可以先提交给 Laravel,我们看下他们是怎么处理的。 |
比如,模型事件里,直接拿修改后的数据,会是什么情况? |
@limingxinleo 模型的update方法实际使用的是database的Builder,如果修改 public function updateOrCreate(array $attributes, array $values = [])
{
return tap($this->firstOrNew($attributes), function ($instance) use ($values) {
// $instance->fill($values)->save(); 原来的代码
$instance->newQuery()->update($values); // 改动后的代码
});
} |
尽量别改。我建议你先给 Laravel 提交 PR 比较好。 |
When the "ct" attribute of the Foo model is set to cast.
In the updateOrCreate method, an Expression expression is used.
The following warning will be issued