gpt4 book ai didi

symfony2 Doctrine 允许空值吗?

转载 作者:行者123 更新时间:2023-12-03 07:06:07 26 4
gpt4 key购买 nike

所以,我对 symfony 还很陌生,但我学得很快...我创建了一个实体和一个临时文件(我忘记了实际上是如何做到的,但它是通过命令行实现的)..

该实体是使用以下内容创建的:

namespace Ecs\CrmBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Ecs\CrmBundle\Entity\TimeClock
*/
class TimeClock
{
/**
* @var integer $id
*/
private $id;

/**
* @var datetime $in1
*/
private $in1;

/**
* @var datetime $out1
*/
private $out1;

/**
* @var datetime $in2
*/
private $in2;

/**
* @var datetime $out2
*/
private $out2;

/**
* @var datetime $in3
*/
private $in3;

/**
* @var datetime $out3
*/
private $out3;


/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set in1
*
* @param datetime $in1
* @return TimeClock
*/
public function setin1($in1)
{
$this->in1 = $in1;
return $this;
}

/**
* Get in1
*
* @return datetime
*/
public function getin1()
{
return $this->in1;
}

/**
* Set in2
*
* @param datetime $in2
* @return TimeClock
*/
public function setin2($in2)
{
$this->in2 = $in2;
return $this;
}

/**
* Get in2
*
* @return datetime
*/
public function getin2()
{
return $this->in2;
}

/**
* Set in3
*
* @param datetime $in3
* @return TimeClock
*/
public function setin3($in3)
{
$this->in3 = $in3;
return $this;
}

/**
* Get in3
*
* @return datetime
*/
public function getin3()
{
return $this->in3;
}

/**
* Set in4
*
* @param datetime $in4
* @return TimeClock
*/
public function setin4($in4)
{
$this->in4 = $in4;
return $this;
}

/**
* Get in4
*
* @return datetime
*/
public function getin4()
{
return $this->in4;
}

/**
* Set in5
*
* @param datetime $in5
* @return TimeClock
*/
public function setin5($in5)
{
$this->in5 = $in5;
return $this;
}

/**
* Get in5
*
* @return datetime
*/
public function getin5()
{
return $this->in5;
}

/**
* Set in6
*
* @param datetime $in6
* @return TimeClock
*/
public function setin6($in6)
{
$this->in6 = $in6;
return $this;
}

/**
* Get in6
*
* @return datetime
*/
public function getin6()
{
return $this->in6;
}
/**
* @var Ecs\AgentManagerBundle\Entity\User
*/
private $noteBy;


/**
* Set noteBy
*
* @param Ecs\AgentManagerBundle\Entity\User $noteBy
* @return TimeClock
*/
public function setNoteBy(\Ecs\AgentManagerBundle\Entity\User $noteBy = null)
{
$this->noteBy = $noteBy;
return $this;
}

/**
* Get noteBy
*
* @return Ecs\AgentManagerBundle\Entity\User
*/
public function getNoteBy()
{
return $this->noteBy;
}
/**
* @var datetime $in1
*/
private $in1;

/**
* @var datetime $out1
*/
private $out1;

/**
* @var datetime $in2
*/
private $in2;

/**
* @var datetime $out2
*/
private $out2;

/**
* @var datetime $in3
*/
private $in3;

/**
* @var datetime $out3
*/
private $out3;

/**
* @var varchar $totaltime
*/
private $totaltime;

/**
* @var datetime $daydate
*/
private $daydate;


/**
* Set in1
*
* @param datetime $in1
* @return TimeClock
*/
public function setIn1($in1)
{
$this->in1 = $in1;
return $this;
}

/**
* Get in1
*
* @return datetime
*/
public function getIn1()
{
return $this->in1;
}

/**
* Set out1
*
* @param datetime $out1
* @return TimeClock
*/
public function setOut1($out1)
{
$this->out1 = $out1;
return $this;
}

/**
* Get out1
*
* @return datetime
*/
public function getOut1()
{
return $this->out1;
}

/**
* Set in2
*
* @param datetime $in2
* @return TimeClock
*/
public function setIn2($in2)
{
$this->in2 = $in2;
return $this;
}

/**
* Get in2
*
* @return datetime
*/
public function getIn2()
{
return $this->in2;
}

/**
* Set out2
*
* @param datetime $out2
* @return TimeClock
*/
public function setOut2($out2)
{
$this->out2 = $out2;
return $this;
}

/**
* Get out2
*
* @return datetime
*/
public function getOut2()
{
return $this->out2;
}

/**
* Set in3
*
* @param datetime $in3
* @return TimeClock
*/
public function setIn3($in3)
{
$this->in3 = $in3;
return $this;
}

/**
* Get in3
*
* @return datetime
*/
public function getIn3()
{
return $this->in3;
}

/**
* Set out3
*
* @param datetime $out3
* @return TimeClock
*/
public function setOut3($out3)
{
$this->out3 = $out3;
return $this;
}

/**
* Get out3
*
* @return datetime
*/
public function getOut3()
{
return $this->out3;
}

/**
* Set totaltime
*
* @param varchar $totaltime
* @return TimeClock
*/
public function setTotaltime(\varchar $totaltime)
{
$this->totaltime = $totaltime;
return $this;
}

/**
* Get totaltime
*
* @return varchar
*/
public function getTotaltime()
{
return $this->totaltime;
}

/**
* Set daydate
*
* @param datetime $daydate
* @return TimeClock
*/
public function setDaydate($daydate)
{
$this->daydate = $daydate;
return $this;
}

/**
* Get daydate
*
* @return datetime
*/
public function getDaydate()
{
return $this->daydate;
}
}

然后,当我这样做时,我想到了 Doctrine :生成:实体的事情(我可能完全错了——我忘记了我做了什么来创建它)..

它生成一个 timeclock.orm.yml 并在数据库中创建表或类似的东西..

timeclock.orm.yml 有这个:

Ecs\CrmBundle\Entity\TimeClock:
type: entity
table: null
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
in1:
type: datetime
out1:
type: datetime
in2:
type: datetime
out2:
type: datetime
in3:
type: datetime
out3:
type: datetime
totaltime:
type: string
daydate:
type: datetime
manyToOne:
noteBy:
targetEntity: Ecs\AgentManagerBundle\Entity\User
lifecycleCallbacks: { }

问题是,totaltime,所有inout字段都需要默认为NULL,但我找不到如何做到这一点.. 在我来到这里之前,我一直在寻找过去 30 分钟的时间,试图弄清楚..

然后,一旦我编辑了我需要的任何文件,如何使其也在数据库中更新?

最佳答案

我一直在寻找解决方案,并对已接受的解决方案不满意。[编辑:虽然我现在知道这是因为我使用了注释]。我发现对我有用的方法是设置可为空:

/**
* @ORM\Column(type="varchar", nullable=true)
*/
private $totaltime = null;

关于symfony2 Doctrine 允许空值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9985531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com