hyperf / hyperf/hyperf

[BUG] 使用 CamelCase 时,firstOrCreate 无法正常工作

Open
#2,600 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
PHP
Stars
6.9k
Forks
1.3k
Avg merge
4h 21m
Merged PRs (30d)
4

Description

### Description:

表 `user_data {user_id, created_at}`, user_id 为主键

使用 CamelCase 后,设置 $fillable = [‘user_id’]
`UserData::query()->firstOrCreate(['userId' => $userId], [ ]);` 会生成查询语句
```select * from `user_data` where (`userId` = 1) limit 1``` 然而表里没有userId字段

`UserData::query()->firstOrCreate(['user_id' => $userId], [ ]);` 能正常查询但插入时生成
```insert into `user_data` (`created_at`) values (2020-09-29 21:31:34)```

这是因为 CamelCase 把 $fillable 转成 ['userId'] 了, 导致参数 user_id 无法 fill

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.