2017-12-18 2 views
0

Ich habe 2 Einheiten - Produkt und Kategorie. Aber ich habe in symfony dev Symbolleiste, um die Fehler - Ungültige Entities 2.Ungültige Entitäten Kategorie und Produkt

Der genaue Fehler ist:

Entities Mapping 

Class Mapping errors 
AppBundle\Entity\category 
The association AppBundle\Entity\category#products refers to the owning side field AppBundle\Entity\Product#category which does not exist. 
AppBundle\Entity\Product  
The association AppBundle\Entity\Product#categoryId refers to the inverse side field AppBundle\Entity\category#product which does not exist.here 

ich oft beheben, um das relastion folgende symfony docs habe versucht, aber es dosn't Werke .

Also, bitte, sagen würde, bin ich falsch ....

Hier sind meine zwei Entitäten:

Produkt

<?php 

namespace AppBundle\Entity; 
use Symfony\Component\HttpFoundation\Response; 
use Symfony\Component\Validator\Constraints as Assert; 
use Doctrine\ORM\Mapping as ORM; 

/** 
* Product 
* 
* @ORM\Table(name="products") 
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository") 
*/ 
class Product 
{ 
    /** 
    * @var int 
    * 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="name", type="string", length=255) 
    */ 
    private $name; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="sku", type="string", length=255, unique=true) 
    */ 
    private $sku; 

    /** 
    * 
    * @ORM\ManyToOne(targetEntity="AppBundle\Entity\category", inversedBy="product") 
    * @ORM\JoinColumn(name="categoryId", referencedColumnName="id") 
    */ 

    private $categoryId; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="image", type="string", length=255, nullable=true) 
    * @Assert\File(
    *  maxSize="5242880", 
    *  mimeTypes = { 
    *   "image/png", 
    *   "image/jpeg", 
    *   "image/jpg", 
    *   "image/gif", 
    *  } 
    *) 
    */ 
    private $image; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="description", type="text", nullable=true) 
    */ 
    private $description; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="price", type="decimal", precision=10, scale=2, nullable=true) 
    */ 
    private $price; 

    /** 
    * @var bool 
    * 
    * @ORM\Column(name="isActive", type="boolean", nullable=true) 
    */ 
    private $isActive; 

    /** 
    * @var int 
    * 
    * @ORM\Column(name="quantity", type="integer", nullable=true) 
    */ 
    private $quantity; 

    /** 
    * @var decimal 
    */ 
    private $percent; 
    /** 
    * @var decimal 
    */ 
    private $endPrice; 


    /** 
    * Get id 
    * 
    * @return int 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return Product 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

    /** 
    * Get name 
    * 
    * @return string 
    */ 
    public function getName() 
    { 
     return $this->name; 
    } 

    /** 
    * Set sku 
    * 
    * @param string $sku 
    * 
    * @return Product 
    */ 
    public function setSku($sku) 
    { 
     $this->sku = $sku; 

     return $this; 
    } 

    /** 
    * Get sku 
    * 
    * @return string 
    */ 
    public function getSku() 
    { 
     return $this->sku; 
    } 

    /** 
    * Set categoryId 
    * 
    * @param integer $categoryId 
    * 
    * @return Product 
    */ 
    public function setCategoryId($categoryId) 
    { 
     $this->categoryId = $categoryId; 

     return $this; 
    } 

    /** 
    * Get categoryId 
    * 
    * @return int 
    */ 
    public function getCategoryId() 
    { 
     return $this->categoryId; 
    } 

    /** 
    * Set image 
    * 
    * @param string $image 
    * 
    * @return Product 
    */ 
    public function setImage($image) 
    { 

     $this->image = $image; 

     return $this; 
    } 

    /** 
    * Get image 
    * 
    * @return string 
    */ 
    public function getImage() 
    { 
     return $this->image; 
    } 

    /** 
    * Set description 
    * 
    * @param string $description 
    * 
    * @return Product 
    */ 
    public function setDescription($description) 
    { 
     $this->description = $description; 

     return $this; 
    } 

    /** 
    * Get description 
    * 
    * @return string 
    */ 
    public function getDescription() 
    { 
     return $this->description; 
    } 

    /** 
    * Set price 
    * 
    * @param string $price 
    * 
    * @return Product 
    */ 
    public function setPrice($price) 
    { 
     $this->price = $price; 

     return $this; 
    } 

    /** 
    * Get price 
    * 
    * @return string 
    */ 
    public function getPrice() 
    { 
     return $this->price; 
    } 

    /** 
    * Set isActive 
    * 
    * @param boolean $isActive 
    * 
    * @return Product 
    */ 
    public function setIsActive($isActive) 
    { 
     $this->isActive = $isActive; 

     return $this; 
    } 

    /** 
    * Get isActive 
    * 
    * @return bool 
    */ 
    public function getIsActive() 
    { 
     return $this->isActive; 
    } 

    /** 
    * Set quantity 
    * 
    * @param integer $quantity 
    * 
    * @return Product 
    */ 
    public function setQuantity($quantity) 
    { 
     $this->quantity = $quantity; 

     return $this; 
    } 

    /** 
    * Get quantity 
    * 
    * @return int 
    */ 
    public function getQuantity() 
    { 
     return $this->quantity; 
    } 

    /** 
    * @return decimal 
    */ 
    public function getPercent() 
    { 
     return $this->percent; 
    } 

    /** 
    * @param decimal $percent 
    */ 
    public function setPercent($percent) 
    { 
     if(null != $percent) { 
      $this->percent = $percent; 
     } 
    } 

    /** 
    * @return decimal 
    */ 
    public function getEndPrice() 
    { 
     return $this->endPrice; 
    } 

    /** 
    * @param decimal $endPrice 
    */ 
    public function setEndPrice($endPrice) 
    { 
     $this->endPrice = $endPrice; 
    } 

} 

........... .................................................. .................................................. .................................................. .................................................. ... Kategorie

<?php 

namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Doctrine\Common\Collections\ArrayCollection; 

/** 
* category 
* 
* @ORM\Table(name="category") 
* @ORM\Entity(repositoryClass="AppBundle\Repository\categoryRepository") 
*/ 
class category 
{ 
    /** 
    * @var int 
    * 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="name", type="string", length=255) 
    */ 
    private $name; 

    /** 
    * @var int 
    * 
    * @ORM\Column(name="parent", type="integer", nullable=true) 
    */ 
    private $parent; 

    /** 
    * @var bool 
    * 
    * @ORM\Column(name="isActive", type="boolean", nullable=true) 
    */ 
    private $isActive; 

    /** 
    * @ORM\OneToMany(targetEntity="AppBundle\Entity\Product" , mappedBy="category") 
    */ 
    private $products; 

    public function __construct() 
    { 
     $this->products = new ArrayCollection(); 
    } 

    /** 
    * Get id 
    * 
    * @return int 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return category 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

    /** 
    * Get name 
    * 
    * @return string 
    */ 
    public function getName() 
    { 
     return $this->name; 
    } 

    /** 
    * Set parent 
    * 
    * @param integer $parent 
    * 
    * @return category 
    */ 
    public function setParent($parent) 
    { 
     $this->parent = $parent; 

     return $this; 
    } 

    /** 
    * Get parent 
    * 
    * @return int 
    */ 
    public function getParent() 
    { 
     return $this->parent; 
    } 

    /** 
    * Set isActive 
    * 
    * @param boolean $isActive 
    * 
    * @return category 
    */ 
    public function setIsActive($isActive) 
    { 
     $this->isActive = $isActive; 

     return $this; 
    } 

    /** 
    * Get isActive 
    * 
    * @return bool 
    */ 
    public function getIsActive() 
    { 
     return $this->isActive; 
    } 

    public function __toString() 
    { 
     return $this->id.""; 
    } 

    /** 
    * @return mixed 
    */ 
    public function getProducts() 
    { 
     return $this->products; 
    } 

    /** 
    * @param mixed $products 
    */ 
    public function setProducts($products) 
    { 
     $this->products = $products; 
    } 

} 

Wie es zu beheben?

Antwort

0

Versuchen in Product-Entität ersetzen diese

private $categoryId; 

Durch diese

private $category; 

Vergessen Sie nicht, den Getter & Setter

0

Versuch zu ändern, dies zu ändern:

* @ORM\ManyToOne(targetEntity="AppBundle\Entity\category", inversedBy="product") 

dazu:

* @ORM\ManyToOne(targetEntity="Category", inversedBy="products") 

und diese:

* @ORM\OneToMany(targetEntity="AppBundle\Entity\Product" , mappedBy="category") 

dazu:

* @ORM\OneToMany(targetEntity="Product" , mappedBy="category") 
Verwandte Themen