我遇到了PHP Hateoas库的问题。
我有一个Doctrine Entity,我希望在关系注释中添加一个排除注释,如documentation中的示例所示。如果我这样做,我会收到以下错误:
[语义错误]注释@Hateoas \不允许排除 在类My \ Entity \ Order上声明。您只能使用此注释 关于这些代码元素:注释
有人知道如何解决这个问题吗?或者它是一个错误或错误的文档?
实体:
<?php
namespace My\Entity;
use Doctrine\ORM\Mapping as ORM;
use Hateoas\Configuration\Annotation as Hateoas;
use JMS\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
* @ORM\Table(name="`order`")
* @ORM\HasLifecycleCallbacks
*
* @Hateoas\Relation(
* "self",
* href = "expr('/order/' ~ object.getId())"),
* exclusion = @Hateoas\Exclusion(
* groups = {"production"}
* )
* )
* @Hateoas\Relation(
* "self",
* href = "expr('/production/' ~ object.getId())"),
* exclusion = @Hateoas\Exclusion(
* groups = {"order"}
* )
* )
*/
class Order
{
}
答案 0 :(得分:2)
似乎我早早关闭了关系注释。
更新实体:
<?php
namespace My\Entity;
use Doctrine\ORM\Mapping as ORM;
use Hateoas\Configuration\Annotation as Hateoas;
use JMS\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
* @ORM\Table(name="`order`")
* @ORM\HasLifecycleCallbacks
*
* @Hateoas\Relation(
* "self",
* href = "expr('/order/' ~ object.getId())",
* exclusion = @Hateoas\Exclusion(
* groups = {"production"}
* )
* )
* @Hateoas\Relation(
* "self",
* href = "expr('/production/' ~ object.getId())",
* exclusion = @Hateoas\Exclusion(
* groups = {"order"}
* )
* )
*/
class Order
{
}