【发布时间】:2016-05-26 20:12:44
【问题描述】:
我有一个抽象的 MappedSuperClass 和另一个名为“User”的类,它是这个 MappedSuperClass 的子类。问题是教义不会生成 User 类的属性。只有 MappedSuperClass 的属性。为什么?
<?php
namespace IsCoconut\Models;
use DateTime;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\MappedSuperclass;
/** @MappedSuperclass */
abstract class BaseEntity
{
/**
* @var int
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/** @Column(type="boolean")
* @var boolean
*/
protected $deleted = false;
/** @Column(name="creation_date_time", type="datetime")
* @var DateTime
*/
protected $creationDateTime;
protected function __construct()
{
$this->creationDateTime = new DateTime();
}
}
这是我的实体,应该由 Doctrine 在数据库中生成
<?php
namespace IsCoconut\Models;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;
/**
* @Entity
* @Table(name="users")
*/
class User extends BaseEntity
{
/**
* @var string
* @ORM\Column(type="string", length=512)
*/
private $forename;
/**
* @var string
* @ORM\Column(type="string", length=512)
*/
private $surname;
/**
* @var string
* @ORM\Column(type="string", length=512, unique=true, nullable=false)
*/
private $email;
/**
* @var string
* @ORM\Column(type="string", length=512, unique=true, nullable=false)
*/
private $passwordHash;
}
这是doctrine orm:schema-tool:create --dump-sql的输出
CREATE TABLE users (id INT NOT NULL, deleted BOOLEAN NOT NULL, creation_date_time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id));
CREATE SEQUENCE users_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
缺少用户的类实体属性!为什么?
【问题讨论】:
-
如果你将属性设为
protected会发生什么? -
什么都没有。我已经试过了
-
您在 User 类文件中的“使用”语句是什么?
-
使用 Doctrine\ORM\Mapping 作为 ORM;使用 Doctrine\ORM\Mapping\Entity;使用 Doctrine\ORM\Mapping\Table;
-
我还注意到在 User 类文件中你有
@ORM\Column'... Maybe you should change everything to@ORM` 以使其保持一致?某处可能存在错误。
标签: php postgresql symfony orm doctrine-orm