#php #symfony #doctrine-orm #doctrine #fixtures
Вопрос:
Я пытаюсь отладить свои приспособления на Symfony, и у меня эта ошибка:
Моя сущность
namespace AppEntity;
use AppRepositoryMappoolRepository;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineCommonCollectionsCollection;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass=MappoolRepository::class)
*/
class Mappool
{
/**
* @ORMId
* @ORMGeneratedValue
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=255)
*/
private $name;
/**
* @ORMColumn(type="string", length=255, nullable=true)
*/
private $thumbnail;
/**
* @ORMColumn(type="integer")
*/
private $follow;
/**
* @ORMColumn(type="datetime")
*/
private $updated_at;
/**
* @ORMColumn(type="datetime")
*/
private $created_at;
/**
* @ORMOneToMany(targetEntity=MappoolMap::class, mappedBy="mappool")
*/
private $mappoolMaps;
/**
* @ORMOneToMany(targetEntity=Step::class, mappedBy="mappool")
*/
private $steps;
/**
* @ORMManyToOne(targetEntity=PoolSet::class, inversedBy="mappools")
* @ORMJoinColumn(nullable=false)
*/
private $poolSet;
/**
* @ORMOneToMany(targetEntity=MappoolFollowed::class, mappedBy="mappool", orphanRemoval=true)
*/
private $mappoolFolloweds;
/**
* @ORMManyToOne(targetEntity=Contributor::class, inversedBy="mappools")
*/
private $Contributor;
public function __construct()
{
$this->mappoolMaps = new ArrayCollection();
$this->steps = new ArrayCollection();
$this->mappoolFolloweds = new ArrayCollection();
}
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 getThumbnail(): ?string
{
return $this->thumbnail;
}
public function setThumbnail(?string $thumbnail): self
{
$this->thumbnail = $thumbnail;
return $this;
}
public function getFollow(): ?int
{
return $this->follow;
}
public function setFollow(int $follow): self
{
$this->follow = $follow;
return $this;
}
public function getUpdatedAt(): ?DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getCreatedAt(): ?DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
/**
* @return Collection|MappoolMap[]
*/
public function getMappoolMaps(): Collection
{
return $this->mappoolMap;
}
public function addMappoolMap(MappoolMap $mappoolMap): self
{
if (!$this->mappoolMaps->contains($mappoolMap)) {
$this->mappoolMaps[] = $mappoolMap;
$mappoolMap->setMappool($this);
}
return $this;
}
public function removeMappoolMap(MappoolMap $mappoolMap): self
{
if ($this->mappoolMaps->removeElement($mappoolMap)) {
// set the owning side to null (unless already changed)
if ($mappoolMap->getMappool() === $this) {
$mappoolMap->setMappool(null);
}
}
return $this;
}
/**
* @return Collection|Step[]
*/
public function getSteps(): Collection
{
return $this->steps;
}
public function addStep(Step $step): self
{
if (!$this->steps->contains($step)) {
$this->steps[] = $step;
$step->setMappool($this);
}
return $this;
}
public function getPoolSet(): ?PoolSet
{
return $this->poolSet;
}
public function setPoolSet(?PoolSet $poolSet): self
{
$this->poolSet = $poolSet;
return $this;
}
/**
* @return Collection|MappoolFollowed[]
*/
public function getMappoolFolloweds(): Collection
{
return $this->mappoolFolloweds;
}
public function addMappoolFollowed(MappoolFollowed $mappoolFollowed): self
{
if (!$this->mappoolFolloweds->contains($mappoolFollowed)) {
$this->mappoolFolloweds[] = $mappoolFollowed;
$mappoolFollowed->setMappool($this);
}
return $this;
}
public function removeStep(Step $step): self
{
if ($this->steps->removeElement($step)) {
// set the owning side to null (unless already changed)
if ($step->getMappool() === $this) {
$step->setMappool(null);
}
}
return $this;
}
public function removeMappoolFollowed(MappoolFollowed $mappoolFollowed): self
{
if ($this->mappoolFolloweds->removeElement($mappoolFollowed)) {
// set the owning side to null (unless already changed)
if ($mappoolFollowed->getMappool() === $this) {
$mappoolFollowed->setMappool(null);
}
}
return $this;
}
public function getContributor(): ?Contributor
{
return $this->Contributor;
}
public function setContributor(?Contributor $Contributor): self
{
$this->Contributor = $Contributor;
return $this;
}
}
Мое Приспособление
<?php
namespace AppDataFixtures;
use AppEntityMappool;
use DoctrineBundleFixturesBundleFixture;
use DoctrineCommonDataFixturesDependentFixtureInterface;
use DoctrinePersistenceObjectManager;
class MappoolFixtures extends Fixture implements DependentFixtureInterface
{
public function load(ObjectManager $manager)
{
for($i = 0; $i < 10; $i ){
$mappool = new Mappool();
$date = new DateTime();
$date->setDate(2021, 12 , 1 $i);
$mappool->setName('name_' . $i);
$mappool->setThumbnail('thumbnail_' . $i);
$mappool->setFollow($i);
$mappool->setUpdatedAt($date);
$mappool->setCreatedAt($date);
$mappool->setPoolSet($this->getReference('poolSet_' . $i));
$mappool->setContributor($this->getReference('contributor_' . $i));
$manager->persist($mappool);
$this->addReference('mappool_' . $i, $mappool);
}
$manager->flush();
}
public function getDependencies()
{
return [
ContributorFixtures::class,
];
}
}
Что касается зависимостей, я просто следую сообщению об ошибке, чтобы сгенерировать их (я не понимаю, как доктрина читает светильники).
Ответ №1:
После некоторых исследований это была моя вина : я использую Mappool::class
вместо MappoolFixtures::class
на getDependencies()