I hope you will be able to help because I have been searching for a few days now.
I have a class called "Attributes". In it, there is a parentId which reference a other entry of Attributes.
I want to extend the entity "Attributes" as "Products" with a few extra fields. All the fields are being extended except for the parentId relation.
When I add parent to Products with getter and setter I get a error:
`"Compile Error: Declaration of Products::setParent(?Attributes $parent): Products must be compatible with Attributes::setParent(?Attributes $parent)
: Attributes"`
I have tried a standalone Entity Products with all the fields but the relationship to Attributes causes database relation issues. And it is an extension of Attributes.
Tried different kinds of getters and setters and leaving it out to be extended from the parent.
Have been searching the web for a answer but have not seen inheritance with a internal relationship.
Attributes class:
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class Attributes
{
/**
* @ORM\Id()
* @ORM\Column(type="string", length=255)
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $val;
/**
* @ORM\Column(type="string", length=255)
*/
private $category;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Attributes")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parent;
}
Products class:
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class Products extends Attributes
{
/**
* @ORM\Column(type="string", length=255)
*/
private $newField1;
/**
* @ORM\Column(type="string", length=255)
*/
private $newField2;
}
I would like to know why the internal relationship "Parent" isn't extended and I would love to know how to get the parentId in the extended class.