Компания имеет отношение OneToMany к Адресной компании. Действия PUT и POST не содержат ошибок или ошибок.
Адреса и адреса компаний являются пустым ответом, когда я запрашиваю у API с почтальоном. (Метод GET)
Субъект компании:
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\CompanyRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Company implements \JsonSerializable
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=150, nullable=true)
*/
private $taxOffice;
/**
* @ORM\Column(type="string", length=15, nullable=true)
*/
private $taxNumber;
/**
* @ORM\Column(type="boolean")
*/
private $isBranch;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $establishment;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="companies")
*/
private $mainBranch;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Company", mappedBy="mainBranch")
*/
private $companies;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Definition")
* @ORM\JoinColumn(nullable=false)
* @Assert\NotBlank()
*/
private $companyType;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime")
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=13, nullable=true)
*/
private $telephone;
/**
* @ORM\Column(type="string", length=13, nullable=true)
*/
private $mobilePhone;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $kepAddress;
/**
* @ORM\Column(type="string", length=13, nullable=true)
*/
private $fax;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Person", mappedBy="company")
*/
private $people;
/**
* @ORM\Column(type="string", length=150)
*/
private $companyName;
/**
* @ORM\Column(type="string", length=200)
*/
private $companyTitle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $email;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="string", length=25, nullable=true)
*/
private $tradeRegisterNumber;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Address", mappedBy="company")
*/
private $addresses;
/**
* Specify data which should be serialized to JSON
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
return array(
"id" => $this->id,
"mainBranch" => $this->mainBranch,
"companyName" => $this->companyName,
"companyTitle" => $this->companyTitle,
"taxOffice" => $this->taxOffice,
"taxNumber" => $this->taxNumber,
"isBranch" => $this->isBranch,
"companyType" => $this->companyType,
"telephone" => $this->telephone,
"mobilePhone" => $this->mobilePhone,
"kepAddress" => $this->kepAddress,
"fax" => $this->fax,
"addresses" => $this->addresses,
"companies" => $this->companies,
"establishment" => null === $this->establishment ? '' : $this->establishment->format('Y-m-d H:i:s'),
'createdAt' => null === $this->createdAt ? '' : $this->createdAt->format('Y-m-d H:i:s'),
'updatedAt' => null === $this->updatedAt ? '' : $this->updatedAt->format('Y-m-d H:i:s')
);
}
}
И адрес объекта:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\AddressRepository")
* @ORM\HasLifecycleCallbacks
*/
class Address implements \JsonSerializable
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=100)
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\City")
* @ORM\JoinColumn(nullable=false)
*/
private $city;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\District")
* @ORM\JoinColumn(nullable=false)
*/
private $district;
/**
* @ORM\Column(type="string", length=255)
*/
// TODO eğer adres => address olursa POST işleminde this value is invalid hatası veriyor. Bunu araştıralım
private $adres;
/**
* @ORM\Column(type="boolean")
*/
private $isDefault;
/**
* @ORM\Column(type="boolean")
*/
private $isInvoice;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="addresses")
*/
private $company;
/**
* Specify data which should be serialized to JSON
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
return array(
"id" => $this->id,
"city" => $this->city,
"district" => $this->district,
"adres" => $this->adres,
"isDefault" => $this->isDefault,
"isInvoice" => $this->isInvoice,
'createdAt' => null === $this->createdAt ? '' : $this->createdAt->format('Y-m-d H:i:s'),
'updatedAt' => null === $this->updatedAt ? '' : $this->updatedAt->format('Y-m-d H:i:s')
);
}
}
И ответ API:
{
"id": 1,
"mainBranch": null,
"companyName": "Mustapayev AŞ",
"companyTitle": "Mustapayev İnşaat Müt. AŞ",
"taxOffice": null,
"taxNumber": null,
"isBranch": false,
"companyType": {
"id": 8,
"parentDefinition": {
"id": 1,
"parentDefinition": null,
"title": "Kuruluş Tipi"
},
"title": "Anonim Şirket"
},
"telephone": null,
"mobilePhone": null,
"kepAddress": null,
"fax": null,
"addresses": {},
"companies": {},
"establishment": "",
"createdAt": "2019-10-04 14:56:33",
"updatedAt": "2019-10-04 14:56:33"
}