help wantedswoft: db
Métriques du dépôt
- Stars
- (5 572 stars)
- Métriques de merge PR
- (Aucune PR mergée en 30 j)
Description
| Q | A |
|---|---|
| Bug report? | no |
| Feature request? | yes |
| Swoft version | 2.0.9 (by php bin/swoft -V) |
| Swoole version | 4.4.12 (by php --ri swoole) |
| PHP version | 7.3.11 (by php -v) |
| Runtime environment | Ubuntu 18.04 |
Describe the bug 我有个商品表,其中attr_lists保存了json字符串,images保存了 英文逗号分隔的字符串;使用php bin/swoft entity:create 生成Goods.php实体之后,手动修改了这两个字段的getter:
/**
* @return string
*/
public function getImages(): string
{
return $this->images;
}
/**
* @return string|null
*/
public function getAttrLists(): ?string
{
return $this->attrLists;
}
以下是修改后的
/**
* @return array
*/
public function getImages(): array
{
return $this->images ? explode(',', $this->images) : [];
}
/**
* @return array
*/
public function getAttrLists(): ?array
{
return $this->attrLists ? json_decode($this->attrLists, 320) : [];
}
这样在使用Goods模型读取数据没有问题,但在update 或 insert的时候报错如下:

我注意到文档示例有一个字段标注了array,但尝试之后对我没有帮助:

就是想实现TP5和lavael的获取器(转换字段格式)功能,但不影响写入操作,是我的用法不对吗?抱歉我不确定是这个是bug,也没找到咱们swoft的计论区,所以请团队帮助解答疑惑,不胜感激。