symfony2教义允许空值? [英] symfony2 doctrine allow null values?

查看:84
本文介绍了symfony2教义允许空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我还是非常新的symfony,但我正在快速学习...我创建了一个实体和一个crud(我忘了我是如何做到的,但它是通过命令行)..

So, I'm still REALLY new to symfony but i'm learning quickly... I created an entity and a crud (i forget how I did it actually but it was via the command line)..

该实体是在其中创建的:

The entity was created with this in it:



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;
    }
}

然后当我想到这个教条:生成:实体的事情(我可能是完全错误的 - 我忘了我做了什么来创建它)..

Then when I did i think the doctrine:generate:entities thing (i could be completely wrong -- i forget what i did to create it)..

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

It generates a timeclock.orm.yml and creates the table in the database or something like that..

timeclock.orm.yml有这样的:

the timeclock.orm.yml has this:

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 ,而 code>和 out 字段需要默认为NULL,我找不到如何做到这一点..我一直在寻找最后30分钟尝试在我来到这里之前弄清楚。

The problem is, totaltime, and all the in and out fields need to have a default of NULL and I can't find how to do that.. I've been searching for the last 30 minutes trying to figure it out before I came here..

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

Then, once I edit whatever file(s) i need, how do I make it update it in the database too?

推荐答案

直接在实体文件中设置默认值:

Set your default values directly in the entity file:

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

然后添加到您的yml文件:

Then add to your yml file:

    totaltime:
        type: string
        nullable: TRUE

然后如下所示:

php app/console doctrine:schema:update --dump-sql

更新数据库。

但是,需要通过手册中的例子来减慢工作速度。猜测你做的事情真的不会让你变得很远。

However, you really need to slow down and work you way through the examples in the manual. Guessing at how you did things is really not going to get you very far.

这篇关于symfony2教义允许空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆