Reputation: 271
I added to my entity "Category" a field "parentcategory" to be able to connect a category to another category:
class Category
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Category")
* @ORM\JoinColumn(name="parentcategory", referencedColumnName="id")
*
*/
private $parentcategory;
public function getId(): ?int
{
return $this->id;
}
public function getParentcategory(): ?Parentcategory {
return $this->parentcategory;
}
public function setParentcategory(?Parentcategory $parentcategory): self {
$this->parentcategory = $parentcategory;
return $this;
}
I get the error message:
The return type of method "getParentcategory" in class "App\Entity\Category" is invalid.
Upvotes: 0
Views: 47
Reputation: 591
It's actually your setter that is causing issueyou need to set the exact class
public function setParentcategory(?Category $category): self {
$this->parentcategory = $category;
return $this;
Upvotes: 1
Reputation: 2561
Change
public function getParentcategory(): ?Parentcategory {
return $this->parentcategory;
}
public function setParentcategory(?Parentcategory $parentcategory): self {
$this->parentcategory = $parentcategory;
return $this;
}
to
public function getParentcategory(): ?Category {
return $this->parentcategory;
}
public function setParentcategory(?Category $parentcategory): self {
$this->parentcategory = $parentcategory;
return $this;
}
Because in your case return type is invalid class
Upvotes: 1