我有兩個實體,一個客戶端(訪問器被剪斷)<?phpnamespace App\Entity;use ApiPlatform\Core\Annotation\ApiResource;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\Validator\Constraints as Assert;/** * @ApiResource( * collectionOperations={ * "get"={"normalization_context"={"groups"="client:list"}}, * "post" * }, * itemOperations={ * "get"={"normalization_context"={"groups"="client:item"}}, * }, * paginationEnabled=false, * order={"name"="ASC"} * ) * @ORM\Entity(repositoryClass="App\Repository\ClientRepository") */class Client{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") * @Groups({"client:list", "client:item"}) */ private $id; /** * @ORM\Column(type="string", length=255) * @Assert\NotBlank * @Groups({"client:list", "client:item"}) */ private $name; /** * @ORM\OneToMany(targetEntity="App\Entity\Package", mappedBy="client") * @Groups({"client:item"}) */ private $packages; public function __construct() { $this->packages = new ArrayCollection(); }
1 回答

四季花海
TA貢獻1811條經驗 獲得超5個贊
問題一直出在我的固定裝置上,感謝@ihsan 指導我進行調試。
我之前假設我需要做的就是在一個包中鏈接到客戶端:
App\Entity\Package:
package_1:
name: 'Inactive Package For First Client'
createdAt: <dateTime('today -1 year')>
status: 'INACTIVE'
client: '@client_1'
package_2:
name: 'Active Package For First Client'
createdAt: <dateTime('today -1 week')>
status: 'ACTIVE'
client: '@client_1'
但是,為了使測試正常工作,我還必須將包關聯到客戶端:
App\Entity\Client:
client_1:
name: First Client
packages:
- '@package_1'
- '@package_2'
- 1 回答
- 0 關注
- 93 瀏覽
添加回答
舉報
0/150
提交
取消