0

I have some common fields in almost all tables. So I created an AbstractEntity class where I can add fields that are in common.

/**
* @MappedSuperclass
*/
abstract class AbstractEntity
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer", options={"unsigned"=true})
     */
    protected int $id;
    /**
    * @ORM\Column(name="created_at", type="datetime", nullable=false)
    */
    protected string $createdAt;
    
    
    public function getId(): int
    {
        return $this->id;
    }
    
    public function createdAt(): string
    {
        return $this->createdAt;
    }

    public function setShopLocale(string $createdAt): self
    {
        $this->createdAt = $createdAt;

        return $this;
    }
}

Now, I extend Abstractclass in other EntityClass

class Random extends AbstractEntity 
{
}

I am getting following error message when I try to insert record.

Class "App\Entity\Admin\Random" sub class of "App\Entity\Admin\AbstractEntity" is not a valid entity or mapped super class.
nas
  • 2,289
  • 5
  • 32
  • 67
  • 1
    Your Random class still needs to be [annotated as an entity](https://www.doctrine-project.org/projects/doctrine-orm/en/2.13/reference/inheritance-mapping.html#mapped-superclasses). And a bit off-topic but unless you are supporting legacy code then you probably want to switch to attributes. – Cerad Jan 20 '23 at 13:55
  • Also off-topic but random is also a mysql key word. It is not reserved but it's probably best to avoid such words. It is possible that you just picked a name at, ahem, random in which case you can disregard this comment. – Cerad Jan 20 '23 at 15:32

0 Answers0