优化CURD代码生成关联
This commit is contained in:
@@ -581,6 +581,13 @@ class Crud extends Backend
|
||||
|
||||
private function parseModelMethods($field, &$modelData): void
|
||||
{
|
||||
// MySQL bigint/int 时间戳字段:显式声明为 integer,避免 ThinkORM 自动时间戳写入 'now' 字符串
|
||||
if (in_array($field['name'] ?? '', ['create_time', 'update_time', 'createtime', 'updatetime'], true)
|
||||
&& in_array($field['type'] ?? '', ['int', 'bigint'], true)
|
||||
) {
|
||||
$modelData['fieldType'][$field['name']] = 'integer';
|
||||
}
|
||||
|
||||
if (($field['designType'] ?? '') == 'array') {
|
||||
$modelData['fieldType'][$field['name']] = 'json';
|
||||
} elseif (!in_array($field['name'], ['create_time', 'update_time', 'updatetime', 'createtime'])
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->with($this->withJoinTable)
|
||||
{%relationVisibleFields%}
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
|
||||
@@ -50,6 +50,7 @@ trait Backend
|
||||
$res = $this->model
|
||||
->field($this->indexField)
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->with($this->withJoinTable)
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
|
||||
Reference in New Issue
Block a user