Skip to content

Commit

Permalink
表模型中存在下划线的字段名时,使用 Swoft\Helper\StringHelper::camel() 转换 (swoft-cloud/…
Browse files Browse the repository at this point in the history
  • Loading branch information
adotpeng authored and huangzhhui committed Sep 12, 2018
1 parent 8f303d4 commit 7ba66f6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion db/src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,25 @@ public function setAttrs(array $attrs)
* @param array $attributes
*
* $attributes = [
* 'name' => $value
* 'userName' => $value
* ]
* or
* $attributes = [
* 'UserName' => $value
* ]
* or
* $attributes = [
* 'user_name' => $value
* ]
*
* @return \Swoft\Db\Model
*/
public function fill(array $attributes): self
{
foreach ($attributes as $name => $value) {
if (1 === preg_match('/_/', $name)) {
$name = StringHelper::camel($name);
}
$methodName = sprintf('set%s', ucfirst($name));
if (method_exists($this, $methodName)) {
$this->$methodName($value);
Expand Down

0 comments on commit 7ba66f6

Please sign in to comment.