我对准则2有一个大问题,我没有将它与Symfony一起使用,而是将其用作库。
代码胜于冗长的讲话:)
例如,我声明了2个实体。
<?
namespace Evengyl\Entity\User;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class User
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToOne(targetEntity="Evengyl\Entity\User\Address", inversedBy="user", cascade={"persist", "remove"})
*/
private $address;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getAddress(): ?Address
{
return $this->address;
}
public function setAddress(Address $address): self
{
$this->address = $address;
return $this;
}
}
<?
namespace Evengyl\Entity\User;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class Address
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $localite;
/**
* @ORM\OneToOne(targetEntity="Evengyl\Entity\User\User", mappedBy="address", cascade={"persist", "remove"})
*/
private $user;
public function getId(): ?int
{
return $this->id;
}
public function getLocalite(): ?string
{
return $this->localite;
}
public function setLocalite(string $localite): self
{
$this->localite = $localite;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
// set the owning side of the relation if necessary
if ($user->getAddress() !== $this) {
$user->setAddress($this);
}
return $this;
}
}
我的索引测试类包含
$adRepo = $entityManager->getRepository(User::class);
$ad = $adRepo->findOneBy(["id" => 1]);
print_r($ad);
但是,根据我的要求,它就是OneToOne。
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 67112960 bytes) in C:\xampp\htdocs\test_doctrine\index.php
I don't understand what...
使用命令正确的架构,使用命令正确的SDB。
我需要您的帮助!