top-think / top-think/think-orm

getTimestampValue 解析报错

Open
#129 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.