Impossible to generate my fixtures alice hautelook symfony Neither the property "productType" nor one of the methods "getProductType()"

I can’t not generate fixtures in my symfony project.
Previoucly, I had a attribute OnetoMany and i passed to ManytoMany.
I think that error comes from here.

I generate my fixtures with alice fixtures bundle : https://github.com/hautelook/AliceBundle

I use this commande :

./bin/console hautelook:fixtures:load --no-interaction --purge-with-truncate

This result :

  Neither the property "productType" nor one of the methods "getProductType()", "productType()", "isProductType()", "hasProductType()", "__get()" exist and have public access in class "AppEntityProduct".  

My concerned entity :

<?php

declare(strict_types = 1);

namespace AppEntity;

use ApiPlatformCoreAnnotationApiResource;
use AppAnnotationCached;
use AppTraitsContentEntityTrait;
use AppTraitsSeoTrait;
use DateTime;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineCommonCollectionsCollection;
use DoctrineORMMapping as ORM;
use DoctrineORMMappingJoinTable;
use Exception;
use JsonSerializable;
use Serializable;
use SymfonyComponentHttpFoundationFileFile;
use SymfonyComponentHttpFoundationFileUploadedFile;
use SymfonyComponentValidatorConstraints as Assert;
use VichUploaderBundleMappingAnnotation as Vich;

/**
 * Class Product
 *
 * @ORMTable()
 * @ORMEntity(repositoryClass="AppRepositoryProductRepository")
 *
 * @VichUploadable
 * @Cached()
 *
 * @SuppressWarnings(PHPMD.TooManyFields)
 */
class Product implements Serializable, JsonSerializable
{
    use ContentEntityTrait;
    use SeoTrait;

    //<editor-fold desc="Members">

    /**
     * @var string
     *
     * @ORMColumn(type="text")
     *
     * @AssertNotBlank()
     */
    protected $description;

    /**
     * @var string
     *
     * @ORMColumn(type="string", nullable=true)
     */
    protected $packaging;

    /**
     * @var string
     *
     * @ORMColumn(type="string", nullable=true)
     */
    protected $packing;

    /**
     * @var string
     *
     * @ORMColumn(type="string", nullable=true)
     */
    protected $gencod;

    /**
     * @VichUploadableField(mapping="product_picture", fileNameProperty="picture")
     *
     * @AssertImage(mimeTypes = {
     *          "image/png",
     *          "image/jpeg",
     *          "image/jpg",
     *      })
     *
     * @var File
     */
    protected $pictureFile;

    /**
     * @var string
     *
     * @AssertLength(max=100)
     *
     * @ORMColumn(type="string", length=100)
     */
    protected $picture;

    /**
     * @var string
     *
     * @AssertLength(max=255)
     *
     * @ORMColumn(type="string", length=255, nullable=true)
     */
    protected $pdf;

    /**
     * @var File
     *
     * @AssertFile(mimeTypes = {"application/pdf", "application/x-pdf"})
     *
     * @VichUploadableField(mapping="product_pdf", fileNameProperty="pdf")
     */
    protected $pdfFile;

    /**
     * @var Brand
     *
     * @ORMManyToOne(targetEntity="AppEntityBrand", inversedBy="products")
     */
    protected $brand;

    /**
     * @var Collection|ProductType[]
     * @AssertCount(min=1, minMessage="Il faut sélectionner au moins {{ limit }} élément")
     * @ORMManyToMany(targetEntity="AppEntityProduct", inversedBy="products")
     * @JoinTable(name="product_product_type")
     */
    protected $productTypes;

    /**
     * @var Collection|Sector[]
     *
     * @AssertCount(min=1, minMessage="Il faut sélectionner au moins {{ limit }} élément")
     *
     * @ORMManyToMany(targetEntity="AppEntitySector")
     */
    protected $sectors;

    /**
     * @var GemRcn[]
     *
     * @AssertCount(min=1, minMessage="Il faut sélectionner au moins {{ limit }} élément")
     *
     * @ORMManyToMany(targetEntity="AppEntityGemRcn", inversedBy="products")
     */
    protected $gemRcns;

    /**
     * @var Collection|Sample[]
     *
     * @ORMOneToMany(targetEntity="AppEntitySample", mappedBy="product", cascade={"remove"})
     */
    protected $samples;

    /**
     * @var Collection|Product[]
     *
     * @ORMManyToMany(targetEntity="AppEntityProduct")
     */
    protected $products;

    /**
     * @var Collection|Inspiration[]
     *
     * @ORMManyToMany(targetEntity="AppEntityInspiration")
     */
    protected $inspirations;
    /**
     * @var Collection|Product[]
     * Many Product have many Product.
     * @ORMManyToMany(targetEntity="AppEntityProduct")
     * @ORMJoinTable(name="product_scoring",
     *      joinColumns={@ORMJoinColumn(name="current_product", referencedColumnName="id")},
     *      inverseJoinColumns={@ORMJoinColumn(name="next_product", referencedColumnName="id")}
     *      )
     */
    protected $scoring;

    /**
     * @var User[]
     *
     * @ORMManyToMany(targetEntity="AppEntityUser", mappedBy="products")
     */
    protected $users;

    /**
     * @var bool
     *
     * @ORMColumn(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,
            $this->title,
            $this->slug,
            ) = 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;
    }
}

My other entity (ManytoMany) :

<?php

declare(strict_types = 1);

namespace AppEntity;

use AppAnnotationCached;
use AppTraitsContentEntityTrait;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineORMMapping as ORM;
use SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity;



/**
 * Class ProductType
 *
 * @ORMTable()
 * @ORMEntity(repositoryClass="AppRepositoryProductTypeRepository")
 *
 * @UniqueEntity(fields={"title", "universe"})
 *
 * @Cached()
 */
class ProductType implements JsonSerializable
{
    use ContentEntityTrait;

    //<editor-fold desc="Members">
    /**
     * @var Universe
     *
     * @ORMManyToOne(targetEntity="AppEntityUniverse", inversedBy="productTypes", cascade={"persist"})
     */
    protected $universe;

    /**
     * @var Product[]
     *
     * @ORMManyToMany(targetEntity="AppEntityProduct", 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>
}

My fixtures yaml :

AppEntityProduct:
    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']

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *