问题描述
我无法在symfony项目中生成固定装置。 以前,我有一个属性OnetoMany,并传递给ManytoMany。 我认为该错误来自此处。
我用alice装置包{https://github.com/hautelook/AliceBundle
生成装置我使用这个命令:
./bin/console hautelook:fixtures:load --no-interaction --purge-with-truncate
此结果:
Neither the property "productType" nor one of the methods "getProductType()","productType()","isProductType()","hasProductType()","__get()" exist and have public access in class "App\Entity\Product".
我关注的实体:
<?PHP
declare(strict_types = 1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Annotation\Cached;
use App\Traits\ContentEntityTrait;
use App\Traits\SEOTrait;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinTable;
use Exception;
use JsonSerializable;
use Serializable;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* Class Product
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
*
* @Vich\Uploadable
* @Cached()
*
* @SuppressWarnings(PHPMD.TooManyFields)
*/
class Product implements Serializable,JsonSerializable
{
use ContentEntityTrait;
use SEOTrait;
//<editor-fold desc="Members">
/**
* @var string
*
* @ORM\Column(type="text")
*
* @Assert\NotBlank()
*/
protected $description;
/**
* @var string
*
* @ORM\Column(type="string",nullable=true)
*/
protected $packaging;
/**
* @var string
*
* @ORM\Column(type="string",nullable=true)
*/
protected $packing;
/**
* @var string
*
* @ORM\Column(type="string",nullable=true)
*/
protected $gencod;
/**
* @Vich\UploadableField(mapping="product_picture",fileNameProperty="picture")
*
* @Assert\Image(mimeTypes = {
* "image/png",* "image/jpeg",* "image/jpg",* })
*
* @var File
*/
protected $pictureFile;
/**
* @var string
*
* @Assert\Length(max=100)
*
* @ORM\Column(type="string",length=100)
*/
protected $picture;
/**
* @var string
*
* @Assert\Length(max=255)
*
* @ORM\Column(type="string",length=255,nullable=true)
*/
protected $pdf;
/**
* @var File
*
* @Assert\File(mimeTypes = {"application/pdf","application/x-pdf"})
*
* @Vich\UploadableField(mapping="product_pdf",fileNameProperty="pdf")
*/
protected $pdfFile;
/**
* @var Brand
*
* @ORM\ManyToOne(targetEntity="App\Entity\Brand",inversedBy="products")
*/
protected $brand;
/**
* @var Collection|ProductType[]
* @Assert\Count(min=1,minMessage="Il faut sélectionner au moins {{ limit }} élément")
* @ORM\ManyToMany(targetEntity="App\Entity\Product",inversedBy="products")
* @JoinTable(name="product_product_type")
*/
protected $productTypes;
/**
* @var Collection|Sector[]
*
* @Assert\Count(min=1,minMessage="Il faut sélectionner au moins {{ limit }} élément")
*
* @ORM\ManyToMany(targetEntity="App\Entity\Sector")
*/
protected $sectors;
/**
* @var GemRcn[]
*
* @Assert\Count(min=1,minMessage="Il faut sélectionner au moins {{ limit }} élément")
*
* @ORM\ManyToMany(targetEntity="App\Entity\GemRcn",inversedBy="products")
*/
protected $gemRcns;
/**
* @var Collection|Sample[]
*
* @ORM\OnetoMany(targetEntity="App\Entity\Sample",mappedBy="product",cascade={"remove"})
*/
protected $samples;
/**
* @var Collection|Product[]
*
* @ORM\ManyToMany(targetEntity="App\Entity\Product")
*/
protected $products;
/**
* @var Collection|Inspiration[]
*
* @ORM\ManyToMany(targetEntity="App\Entity\Inspiration")
*/
protected $inspirations;
/**
* @var Collection|Product[]
* Many Product have many Product.
* @ORM\ManyToMany(targetEntity="App\Entity\Product")
* @ORM\JoinTable(name="product_scoring",* joinColumns={@ORM\JoinColumn(name="current_product",referencedColumnName="id")},* inverseJoinColumns={@ORM\JoinColumn(name="next_product",referencedColumnName="id")}
* )
*/
protected $scoring;
/**
* @var User[]
*
* @ORM\ManyToMany(targetEntity="App\Entity\User",mappedBy="products")
*/
protected $users;
/**
* @var bool
*
* @ORM\Column(type="boolean",options={"default": true})
*/
protected $enabled = true;
/**
* @var bool
*
* Field not mapped
*/
protected $favorite = false;
/**
* @var string
*
* Field not mapped
*/
protected $picturePath;
/**
* @var string
*
* Field not mapped
*/
protected $previewPath;
//</editor-fold>
/**
* Product constructor.
*/
public function __construct()
{
$this->sectors = new ArrayCollection();
$this->productTypes = new ArrayCollection();
$this->samples = new ArrayCollection();
$this->products = new ArrayCollection();
$this->users = new ArrayCollection();
$this->gemRcns = new ArrayCollection();
$this->scoring = new ArrayCollection();
}
/**
* @param User $user
*
* @return bool
*/
public function toggleUser(User $user): bool
{
if ($this->isFavorite($user)) {
$this->removeUser($user);
return false;
}
$this->addUser($user);
return true;
}
/**
* @param User $user
*
* @return bool
*/
public function isFavorite(?User $user): bool
{
return $this->users->contains($user);
}
/**
* {@inheritdoc}
*/
public function jsonSerialize(): array
{
return [
'id' => $this->id,'title' => $this->title,'slug' => $this->slug,'packaging' => $this->packaging,'brand' => $this->brand->__toString(),'isFavorite' => $this->favorite,'picturePath' => $this->picturePath,'previewPath' => $this->previewPath,'picture' => $this->picture
];
}
/**
* {@inheritdoc}
*/
public function serialize()
{
return serialize([
$this->id,$this->title,$this->slug,]);
}
/**
* {@inheritdoc}
*/
public function unserialize($serialized)
{
list(
$this->id,) = unserialize($serialized,['allowed_classes' => true]);
}
//<editor-fold desc="Getters">
/**
* @return null|File
*/
public function getPictureFile(): ?File
{
return $this->pictureFile;
}
/**
* @return null|string
*/
public function getPicture(): ?string
{
return $this->picture;
}
/**
* @return string
*/
public function getPdf(): ?string
{
return $this->pdf;
}
/**
* @return File
*/
public function getPdfFile(): ?File
{
return $this->pdfFile;
}
/**
* @return string
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return string
*/
public function getPackaging(): ?string
{
return $this->packaging;
}
/**
* @return string
*/
public function getPacking(): ?string
{
return $this->packing;
}
/**
* @return string
*/
public function getGencod(): ?string
{
return $this->gencod;
}
/**
* @return Brand
*/
public function getBrand(): ?Brand
{
return $this->brand;
}
/**
* @return ProductType[]|Collection
*/
public function getProductTypes(): Collection
{
return $this->productTypes;
}
/**
* @return Sector[]|Collection
*/
public function getSectors(): Collection
{
return $this->sectors;
}
/**
* @return Product[]|Collection
*/
public function getProducts(): Collection
{
return $this->products;
}
/**
* @return GemRcn[]|Collection
*/
public function getGemRcns(): Collection
{
return $this->gemRcns;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->enabled;
}
//</editor-fold>
//<editor-fold desc="Setters">
/**
* @param string $picture
*
* @return static
*/
public function setPicture(?string $picture): self
{
$this->picture = $picture;
return $this;
}
/**
* @param File $pictureFile
*
* @return static
* @throws Exception
*/
public function setPictureFile(?File $pictureFile): self
{
$this->pictureFile = $pictureFile;
if ($pictureFile instanceof UploadedFile && $pictureFile->getError() === 0) {
$this->updatedAt = new DateTime();
}
return $this;
}
/**
* @param string $pdf
*
* @return self
*/
public function setPdf(?string $pdf): self
{
$this->pdf = $pdf;
return $this;
}
/**
* @param File $pdfFile
*
* @return self
* @throws Exception
*/
public function setPdfFile(?File $pdfFile): self
{
$this->pdfFile = $pdfFile;
if ($pdfFile instanceof UploadedFile && $pdfFile->getError() === 0) {
$this->updatedAt = new DateTime();
}
return $this;
}
/**
* @param string $description
*
* @return self
*/
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
/**
* @param string $packaging
*
* @return self
*/
public function setPackaging(string $packaging): self
{
$this->packaging = $packaging;
return $this;
}
/**
* @param string $packing
*
* @return self
*/
public function setPacking(string $packing): self
{
$this->packing = $packing;
return $this;
}
/**
* @param string $gencod
*
* @return self
*/
public function setGencod(string $gencod): self
{
$this->gencod = $gencod;
return $this;
}
/**
* @param Brand $brand
*
* @return self
*/
public function setBrand(Brand $brand): self
{
$this->brand = $brand;
return $this;
}
/**
* @param ProductType $productType
*
* @return self
*/
public function addProductType(ProductType $productType): self
{
$this->productTypes->add($productType);
return $this;
}
/**
* @param bool $enabled
*
* @return self
*/
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
/**
* @param bool $isFavorite
*
* @return self
*/
public function setFavorite(bool $isFavorite): self
{
$this->favorite = $isFavorite;
return $this;
}
/**
* @param string $path
*
* @return self
*/
public function setPicturePath(string $path): self
{
$this->picturePath = $path;
return $this;
}
/**
* @param string $path
*
* @return self
*/
public function setPreviewPath(string $path): self
{
$this->previewPath = $path;
return $this;
}
//</editor-fold>
//<editor-fold desc="Collection">
/**
* @param Sector $sector
*
* @return self
*/
public function removeSector(Sector $sector): self
{
$this->sectors->removeElement($sector);
return $this;
}
/**
* @param ProductType $productType
*
* @return self
*/
public function removeProductType(ProductType $productType): self
{
$this->productTypes->removeElement($productType);
return $this;
}
/**
* @param Sector $sector
*
* @return self
*/
public function addSector(Sector $sector): self
{
$this->sectors->add($sector);
return $this;
}
/**
* @param Sample $sample
*
* @return self
*/
public function removeSample(Sample $sample): self
{
$this->samples->removeElement($sample);
return $this;
}
/**
* @param Sample $sample
*
* @return self
*/
public function addSample(Sample $sample): self
{
$this->samples->add($sample);
return $this;
}
/**
* @param Product $product
*
* @return self
*/
public function removeProduct(Product $product): self
{
$this->products->removeElement($product);
return $this;
}
/**
* @param Product $product
*
* @return self
*/
public function addProduct(Product $product): self
{
$this->products->add($product);
return $this;
}
/**
* @param User $user
*
* @return self
*/
public function addUser(User $user): self
{
$this->users->add($user);
$user->addProduct($this);
return $this;
}
/**
* @param User $user
*
* @return self
*/
public function removeUser(User $user): self
{
$this->users->removeElement($user);
$user->removeProduct($this);
return $this;
}
/**
* @param GemRcn $gemRcn
*
* @return self
*/
public function addGemRcn(GemRcn $gemRcn): self
{
$this->gemRcns->add($gemRcn);
$gemRcn->addProduct($this);
return $this;
}
/**
* @param GemRcn $gemRcn
*
* @return self
*/
public function removeGemRcn(GemRcn $gemRcn): self
{
$this->gemRcns->removeElement($gemRcn);
$gemRcn->removeProduct($this);
return $this;
}
public function getScoring(){
return $this->scoring;
}
/**
* @param Product $product
* @return Product
*/
public function addScoring(Product $product) :self
{
$this->scoring->add($product);
return $this;
}
/**
* @param Product $product
* @return self
*/
public function removeScoring(Product $product): self
{
$this->scoring->removeElement($product);
return $this;
}
}
我的另一个实体(ManytoMany):
<?PHP
declare(strict_types = 1);
namespace App\Entity;
use App\Annotation\Cached;
use App\Traits\ContentEntityTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Class ProductType
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="App\Repository\ProductTypeRepository")
*
* @UniqueEntity(fields={"title","universe"})
*
* @Cached()
*/
class ProductType implements \JsonSerializable
{
use ContentEntityTrait;
//<editor-fold desc="Members">
/**
* @var Universe
*
* @ORM\ManyToOne(targetEntity="App\Entity\Universe",inversedBy="productTypes",cascade={"persist"})
*/
protected $universe;
/**
* @var Product[]
*
* @ORM\ManyToMany(targetEntity="App\Entity\Product",mappedBy="productTypes",cascade={"remove"})
*/
protected $products;
//</editor-fold>
/**
* Product Type constructor.
*/
public function __construct()
{
$this->products = new ArrayCollection();
}
/**
* {@inheritdoc}
*/
public function jsonSerialize(): array
{
return [
'id' => $this->id,'title' => $this->title,];
}
//<editor-fold desc="Getters">
/**
* @return Product[]
*/
public function getProducts()
{
return $this->products;
}
/**
* @return Universe
*/
public function getUniverse(): ?Universe
{
return $this->universe;
}
//</editor-fold>
//<editor-fold desc="Setters">
/**
* @param Universe $universe
*
* @return self
*/
public function setUniverse(Universe $universe): self
{
$this->universe = $universe;
$universe->addProductType($this);
return $this;
}
//</editor-fold>
//<editor-fold desc="Collection">
/**
* @param Product $product
*
* @return self
*/
public function addProduct(Product $product): self
{
$this->products->add($product);
return $this;
}
/**
* @param Product $product
*
* @return self
*/
public function removeProduct(Product $product): self
{
$this->products->removeElement($product);
return $this;
}
//</editor-fold>
}
我的装置Yaml:
App\Entity\Product:
product_{1..40}:
title: '<sentence(3)>'
description: '<sentence()>'
packaging: '<sentence(3)>'
packing: '<sentence(3)>'
picture: '<filecopy("features/files/image/test-picture.jpg","public/uploads/products",0)>'
brand: '@brand_<numberBetween(1,10)>'
gemRcns: ['@gem_rcn_<numberBetween(1,10)>']
gencod: '<sentence(3)>'
productTypes: ['@product_type_<numberBetween(1,21)>','@product_type_<numberBetween(1,21)>']
sectors: ['@school','@health','@pension','@company','@bakery','@hostel','@retailer']
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)