top-think / top-think/think-orm
getTimestampValue 解析报错
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 437
- Forks
- 188
- PR merge metrics
- No merged PRs in 30d
Description
vendor/topthink/think-orm/src/model/concern/TimeStamp.php
$model->select()->toArray() 时提示传入的是数字,期望是字符串
model中未设置autoWriteTimestamp
解析字段 create_time (int 11 unsigned) 报错
debug后发现是 getTimestampValue 这里的判断
protected function getTimestampValue($value)
{
$type = $this->checkTimeFieldType($this->autoWriteTimestamp);
if (is_string($type) && in_array(strtolower($type), [
'datetime', 'date',
'timestamp',
])) {
$value = $this->formatDateTime($this->dateFormat, $value);
} else {
$value = $this->formatDateTime($this->dateFormat, $value, true);
}
return $value;
}
好奇为什么type为 timestamp 时会当作字符串来处理呢?不是应该进 else里的方法吗?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in vendor/topthink/think-orm/src/model/concern/TimeStamp.php and trace getTimestampValue through checkTimeFieldType and formatDateTime. Reproduce the model->select()->toArray() case with an unsigned int create_time and no autoWriteTimestamp, then determine the expected timestamp conversion. Done means this case no longer reports a numeric value where a string is expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100