【发布时间】:2014-05-22 09:21:29
【问题描述】:
这是我的实体类:
namespace Bits\JobBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Bits\JobBundle\Utils\Jobeet as Jobeet;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Job
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Bits\JobBundle\Entity\JobRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Job
{
/**
* @var \DateTime
* @ORM\Column(name="expires_at", type="datetime")
*/
private $expires_at;
/**
* @var \DateTime
* @ORM\Column(name="created_at", type="datetime")
*/
private $created_at;
/**
* @var \DateTime
*/
private $updated_at;
/**
* @var \Bits\JobBundle\Entity\Category
*/
private $category;
/**
* Set expires_at
* @ORM\PrePersist
* @param \DateTime $expires_at
* @return Job
*/
public function setExpiresAt()
{
$this->expires_at=new \DateTime();
return $this;
}
/**
* Get expires_at
*
* @return \DateTime
*/
public function getExpiresAt()
{
return $this->expires_at;
}
Job.orm.yml
Bits\JobBundle\Entity\Job:
type: entity
table: job
id:
id:
type: integer
generator: {strategy: auto}
fields:
type:
type: string
length: 255
nullable: true
expires_at:
type: datetime
created_at:
type: datetime
updated_at:
type: datetime
nullable: true
manyToOne:
category:
targetEntity: Category
inversedBy: jobs
joinColumn:
name: category_id
referencedColumnName: id
lifeCycleCallbacks:
prePersist: [setCreatedAt, setExpiresAt]
preUpdate: [setUpdatedAt]
我在 expires_at 值中得到空值。
这是 SQL 错误。
执行 'INSERT INTO 作业(类型、公司、徽标、url、位置、位置、描述、how_to_apply、token、is_public、is_activated、email、expires_at、created_at、updated_at、category_id)时发生异常 VALUES (?, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params [null, "test", null, null, "test", "test" , "测试", "测试", "sdfa", 0, null, "asdf", null, null, null, null]:
如何调试?
【问题讨论】:
-
你能提供更多细节吗?你如何填写工作实体?
-
问题不在于填写表格。 expired at 值将自动生成。但是,就我而言,它还没有生成。当我在 setExpiresAt 函数上回显某些内容时,插入操作时不会调用此函数。这意味着我得到了上面的 SQL 语句
-
@SudinManandhar 发布您用于持久化实体的代码
-
我已经添加了 orm.yml 文件
-
为什么同一个实体有2个映射!!