I'm rewriting an old symfony 3 project to symfony 4 and I'm trying to rewrite old fixtures to a new format.
Currently, fixtures are working fine for the most of the files, except for a single one where I got the error: Argument 1 passed to App\Entity\Contents::setCategory() must be an instance of App\Entity\App\Entity\Categories or null, instance of Proxies\__CG__\App\Entity\Categories given.
In the first fixture file (below), the error is in the second line:
$contents1_1 = new Contents(); $contents1_1->setCategory($this->getReference('category-budget')); ... $manager->persist($contents1_1);
I'm defining 'category-budget'
in the second file as follows:
$categoryBudget = new Categories(); $categoryBudget->setParent($categoryAbout); $categoryBudget->setType($this->getReference('type-contents')); ... $manager->persist($categoryBudget); $this->addReference('category-budget', $categoryBudget);
type-contents
are just dummy data. $categoryAbout
is another object of class Categories, with no parent and type-contents
set as type.
My setCategory is as follows:
/** * Set category * * @param Categories|null $category * * @return Contents */public function setCategory(Categories $category = null){ $this->category = $category; return $this;}
What is the issue and how to solve it?