我有以下用户实体和夹具文件,但当我运行app/控制台学说:fixture:load时,我得到以下错误,不知道为什么。如果我删除日期字段,fixture生成fine。我遗漏了什么?谢谢。
错误:无法确定如何将created_at分配给AppBundleEntityUser对象
<?php
namespace AppBundleEntity;
use GedmoMappingAnnotation as Gedmo;
use DoctrineORMMapping as ORM;
/**
* User
*
* @ORMTable()
* @ORMEntity(repositoryClass="AppBundleEntityUserRepository")
*/
class User
{
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORMColumn(name="name", type="string", length=255)
*/
private $name;
/**
* @var string
*
* @ORMColumn(name="role", type="string", length=255)
*/
private $role;
/**
* @var string
*
* @ORMColumn(name="email", type="string", length=255)
*/
private $email;
/**
* @var string
*
* @ORMColumn(name="phone", type="string", length=16)
*/
private $phone;
/**
* @var DateTime
*
* @GedmoTimestampable(on="create")
* @ORMColumn(name="created_at", type="datetime", nullable=true)
*/
private $createdAt;
/**
* @var DateTime
*
* @GedmoTimestampable(on="update")
* @ORMColumn(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
和我的夹具yml:
AppBundleEntityUser:
user{1..10}:
name: <firstName()> <lastName()>
role: employee
email: <email()>
phone: <numberBetween(1555000000, 1555999999)>
created_at: <datetimeBetween('-5 days', 'now')>
updated_at: <datetimeBetween('-5 days', 'now')>
不确定,但我相信命名是不正确的,只是错误所说的。我认为应该是:
createdAt: <datetimeBetween('-5 days', 'now')>
updatedAt: <datetimeBetween('-5 days', 'now')>
恐怕你不能手动设置时间戳字段。在文档和实体示例中,这些字段根本没有设置器。因此,在fixture中,您可以简单地删除created_at
和updated_at
(它们将自动设置):
ppBundleEntityUser:
user{1..10}:
name: <firstName()> <lastName()>
role: employee
email: <email()>
phone: <numberBetween(1555000000, 1555999999)>