I added to my entity “Category” a field “parentcategory” to be able to connect a category to another category:
JavaScript
x
class Category
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMManyToOne(targetEntity="Category")
* @ORMJoinColumn(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 “AppEntityCategory” is invalid.
Advertisement
Answer
Change
JavaScript
public function getParentcategory(): ?Parentcategory {
return $this->parentcategory;
}
public function setParentcategory(?Parentcategory $parentcategory): self {
$this->parentcategory = $parentcategory;
return $this;
}
to
JavaScript
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