这个问题通常是因为ManyToOne实体属性使用了@id注释而不是@iri注释。应该将这些注释改为@iri以指定IRI。例如:
class Order { /** * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") * * @var int */ private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Customer")
* @ORM\JoinColumn(nullable=false)
* @ApiProperty(identifier=true)
*
* @var Customer
*/
private $customer;
}
在这里,将@ApiProperty(identifier=true)替换为@ApiProperty(iri="http://schema.org/customer")。这将指定客户属性的IRI,从而解决了API平台Many to One不期望IRI的问题。
下一篇:API平台模型属性是只读的。