Olá, o erro abaixo apareceu quando eu fazia a aula 4:
PHP Notice: Undefined index: Product in C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php on line 1794
Notice: Undefined index: Product in C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php on line 1794 PHP Warning: Invalid argument supplied for foreach() in C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php on line 1798
Warning: Invalid argument supplied for foreach() in C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php on line 1798 PHP Notice: Undefined index: Product in C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\PersistentCollection.php on line 167
Notice: Undefined index: Product in C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\PersistentCollection.php on line 167 PHP Fatal error: Uncaught Error: Call to a member function setValue() on null in C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\PersistentCollection.php:167 Stack trace:
#0 C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php(511): Doctrine\ORM\PersistentCollection->hydrateAdd(Object(KassioSchaider\PriceStalker\Entity\Price))
#1 C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php(162): Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateRowData(Array, Array)
#2 C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\AbstractHydrator.php(152): Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData()
#3 C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php(967): Doctrine\ORM\Internal\Hyd in C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\PersistentCollection.php on line 167
Fatal error: Uncaught Error: Call to a member function setValue() on null in C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\PersistentCollection.php:167 Stack trace:
#0 C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php(511): Doctrine\ORM\PersistentCollection->hydrateAdd(Object(KassioSchaider\PriceStalker\Entity\Price))
#1 C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php(162): Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateRowData(Array, Array)
#2 C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\AbstractHydrator.php(152): Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData()
#3 C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php(967): Doctrine\ORM\Internal\Hyd in C:\Users\kassi\PhpstormProjects\composer\price-stalker\vendor\doctrine\orm\lib\Doctrine\ORM\PersistentCollection.php on line 167
Depois de muito procurar no código, descobri que era basicamente o mapeamento da minha classe Product, mais especificamente no atributo "mappedBy", como está abaixo:
/**
* @OneToMany(targetEntity="Price", mappedBy="Product", cascade={"remove", "persist"})
*/
private $prices;
Meu erro é que coloquei a propriedade com o valor em Maiúsculo, quando o correto é:
/**
* @OneToMany(targetEntity="Price", mappedBy="product", cascade={"remove", "persist"})
*/
private $prices;
Enfim, só queria compartilhar isso pois não encontrei um tópico sobre. Se alguém souber, explica aí por gentileza o porquê de acontecer isso, tendo em vista que no "targetEntity" por exemplo, colocamos o nome da Entidade normalmente.
Obrigado e desculpa se tiver isso na aula e eu não prestei a atenção :P