MySQL 테이블의 열을 "updated_at"이라고합니다. 날짜 형식이 아니고 null이 아닙니다. Doctine 유형도 datetime입니다. 그것이 내가이 열의 값을 가지고 싶지 않아 생성 된 후 실체 적 업데이트되지 않은 경우Doctrine으로 엔티티 업데이트 시간을 올바르게 설정하는 방법은 무엇입니까?
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 유형을 변경하지 않고이 열을 건너 뛰거나 적절한 값을 설정하는 방법 (올바른 것이므로)?
DoctrineExtensions의 [Timestampable] (https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/timestampable.md)을 사용하고 있습니까? –
Symfony2.2를 doctrine ORM 및 doctrine 번들과 함께 사용합니다. – coviex
예, 어떤 번들이 타임 스탬프 가능 동작을 제공합니까? [StofDoctrineExtensionsBundle] (https://github.com/stof/StofDoctrineExtensionsBundle)? –