【发布时间】:2020-09-14 10:33:47
【问题描述】:
尽管我努力使用类型提示和@var int 注释,但Api Platform 对此属性的解释始终是string。
考虑这个属性:
/**
* @var int $geonameId The ID of a Geonames.org city/place/town
*
* @ORM\Column(type="bigint", options={"unsigned": true}, nullable=true)
* @Assert\Type(type="int", message="Geoname id must be an integer")
*/
protected $geonameId;
public function getGeonameId(): ?int
{
return $this->geonameId;
}
public function setGeonameId(int $geonameId = null): self
{
$this->geonameId = $geonameId;
return $this;
}
我从 Api Platform 得到以下架构:
geonameId string
nullable: true
The ID of a Geonames.org city/place/town
当我尝试提交 "geonameId": 123456 时,我收到以下错误:
类的“geonameId”属性的类型必须是“string”之一(给定“int”)。
我知道 @ApiProperty 注释来自定义属性等,但是当我已经使用类型提示和/或 @var 注释时,我不想为了接受整数而冗长地定义类型。
有人认为我正在做/期待的事情有什么问题吗?提前谢谢...
【问题讨论】:
-
doctrine-project.org/projects/doctrine-orm/en/2.7/reference/… - 看起来 Doctrine 将 BIGINT 映射为字符串。
bigint: Type that maps a database BIGINT to a PHP string.不确定是否可以尝试使用整数?需要考虑的事情.. -
感谢@Bossman,这有效,请回答而不是评论,我将标记为正确。不敢相信这种区别,这确实是有道理的,我只是从没想过这会是罪魁祸首:)
标签: symfony doctrine-orm api-platform.com