MySQL 表中的列称为“updated_at”。它是日期时间类型,不为空。教义类型也是日期时间。
CREATE TABLE `example` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Some\Bundle\Entity\Example:
type: entity
table: examples
fields:
id:
id: true
type: integer
generator:
strategy: IDENTITY
...
createdAt:
type: datetime
column: created_at
updatedAt:
type: datetime
column: updated_at
$e = new Example;
$e->setCreatedAt(new \DateTime);
$em->persist($e);
/* after this I need $e->updatedAt to be MySQL's default 0 (0000-00-00) */
$em->flush();
/* but it will throw
"Integrity constraint violation: 1048 Column 'updated_at' cannot be null"
if I won't set it in Example::__contruct()
which I don't see any reason to do
apart from complying with Doctrine shortcomings. */
如果实体在创建后从未更新,我不想在此列中有任何值。
如何在不更改 MySQL 或 Doctrine 类型的情况下跳过此列或设置适当的值(因为它们是正确的)?