前天使用了composer update升级了webman到1.4.3然后make:model工作不正常了。

euii

Workman Version:4.1.2
PHP Version: 8.1.10
OS:macOS 12.6
webman framework: 1.4.3

数据库连接正常
使用

php webman make:model mngWkInfo

期望生成一个Model类,类的内容带着字段的名称

namespace app\model;

use support\Model;

/**
 * @property string $created_at 
 * @property string $deleted_at 
 * @property integer $id (主键)
 * @property string $idx_code 指数编码
 * @property string $idx_name 指数名称
 * @property string $pct_change 涨跌幅
aindexeodprices.s_dq_pctchange
 * @property string $trade_date 交易日期
 * @property string $updated_at
 */
class MngWkInfo extends Model {
protected $table = 'mng_wk_info';
}

而现在生成的类是

<?php

namespace app\model;

use support\Model;

/**
 *
 */
class MngWkInf extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = null;

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;
}

貌似没有读取表里的内容,我不知道是不是升级了新版本的webman后需要新的配置,我在文档里也没有看到相关的介绍。

995 1 1
1个回答

walkor

make:modelwebman/console组件提供的,一般和webman升级没有关系。
没有生成注释一般是因为命令里没有成功连接到主配置的数据库,或者表不存在,至于为什么需要你自己排查下。
文件 vendor/webman/console/src/Commands/MakeModelCommand.php 的 createModel方法

  • euii 2022-09-25

    了解,我这就去看看。

  • euii 2022-09-25

    经过debug,发现一个问题,我不知道为啥会这样。 上述类中createModel方法第95行的代码,$table = Util::classToName($class); 当我们传入的类名是 mngWkInfo时,$table的返回值是 mng_wk_infos , 自己给字段增加了s后缀,这样,在108行循环的时候,这个表里在库里自然是没有的,我不知道Util::classToName()这个函数为什么会这样

  • walkor 2022-09-25

    前一阵一个开发者发的pr影响到了,等下我修复下

  • walkor 2022-09-25

    执行 composer require webman/console ^1.2.14 升级下webman/console

  • euii 2022-09-25

    好了,👌,谢谢大神。

  • wocall 2023-06-09

    感谢感谢,终于知道如何创建模型了,看的手册,还以为得自己一行一行去反复写呢。:)

年代过于久远,无法发表回答
×
🔝