我有一个带有两个 manyToOne 的实体,想要在序列化期间包装。
namespace AppBundle\Entity\Fleet;
use AppBundle\Entity\Account\Site;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class Equipment
{
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account\Site")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
protected $siteOwner;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account\Contact")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
protected $contactOwner;
}
序列化成
{
"owner": {
"site": {...},
"contact": {...}
}
}
所以我做了一个简单的吸气剂。
/**
* @Groups({"read"})
*/
public function getOwner()
{
return [
'site' => $this->siteOwner,
'contact' => $this->contactOwner,
];
}
Site
并且Contact
实体也是具有工作端点的 ApiResource。但是在序列化过程中出现错误:No resource class found for object of type "AppBundle\Entity\Account\Site".
任何想法 ?
更新
我能够通过 api-platform 演示重现相同的问题。我已经分叉了基本演示,并在评论实体上添加了一个自定义 getter。
得到一样的No resource class found for object of type AppBundle\Entity\Book