Nettrine ORM Attribute zlobí při používání trait
- Michwuanquana
- Člen | 22
Zdravím,
když používám attributes v entitě, tak mám problém s traity.
např. entita User
#[ORM\Entity(repositoryClass: App\Model\Database\Repository\UserRepository::class)]
#[ORM\Table(name: "`user`")]
#[ORM\HasLifecycleCallbacks]
class User extends AbstractEntity
{
use TId;
use TCreatedAt;
use TUpdatedAt;
#[ORM\Column(type: "string", length: 255, nullable: FALSE, unique: false)]
private string $name;
#[ORM\Column(type: "string", length: 255, nullable: FALSE, unique: false)]
private string $surname;
//...
kde TId je:
trait TId
{
#[ORM\Column(type: "integer", nullable: FALSE)]
#[ORM\GeneratedValue]
#[ORM\Id]
private int $id;
//...
Nefunguje, zlobí se, že nemá primární klíč.
No identifier/primary key specified for Entity "App\Model\Database\Entity\User" sub class of "App\Model\Database\Entity\AbstractEntity". Every Entity must have an identifier/primary key.
Pokud je vložen přímo, funguje:
#[ORM\Entity(repositoryClass: App\Model\Database\Repository\UserRepository::class)]
#[ORM\Table(name: "`user`")]
#[ORM\HasLifecycleCallbacks]
class User extends AbstractEntity
{
use TCreatedAt;
use TUpdatedAt;
#[ORM\Column(type: "integer", nullable: FALSE)]
#[ORM\GeneratedValue]
#[ORM\Id]
private int $id;
#[ORM\Column(type: "string", length: 255, nullable: FALSE, unique: false)]
private string $name;
#[ORM\Column(type: "string", length: 255, nullable: FALSE, unique: false)]
private string $surname;
//...
nicméně i TCreatedAt a TUpdatedAt se vloží správně. (bin/console orm:schema-tool:update, v prvním případě zlobí i v prohlížeči stejnou chybou)
S klasickými annotations to funguje i v prvním případě, že by nějaká chyba?