DateTime持续到一个DB列,而不是Symfony 4.4应用程序中的另一个DB列

发布于 2025-01-28 11:44:50 字数 1535 浏览 4 评论 0 原文

我有一个令人困惑的问题,其中我有一个 datetime 对象,它似乎可以持久地并冲入一列,但不是另一列

我已经检查了数据库,数据未写入“保护台”列。

$lifecycle->setRemovalDate($extendedProtectionDate); // this line works
$lifecycle->setProtectionDate($extendedProtectionDate); // this line doesn't
$em = $this->doctrine->getManager();
$em->persist($lifecycle);
$em->flush();

这些字段的定义是相同的:

    /**
     * @var DateTime
     *
     * @ORM\Column(name="removalDate", type="date", nullable=true)
     */
    private $removalDate;

    /**
     * @var DateTime
     *
     * @ORM\Column(name="protectionDate", type="date", nullable=true)
     */
    private $protectionDate;

辅助和突变器也是如此:

   /**
     * @param DateTime|null $removalDate
     *
     * @return Lifecycle
     */
    public function setRemovalDate($removalDate = null) : self
    {
        $this->removalDate = $removalDate;

        return $this;
    }

    /**
     * @return DateTime|null
     */
    public function getRemovalDate() : ?DateTime
    {
        return $this->removalDate;
    }

    /**
     * @param DateTime|null $protectionDate
     *
     * @return Lifecycle
     */
    public function setProtectionDate($protectionDate = null) : self
    {
        $this->protectionDate = $protectionDate;

        return $this;
    }

    /**
     * @return DateTime|null
     */
    public function getProtectionDate() : ?DateTime
    {
        return $this->protectionDate;
    }

I have a baffling issues where I have a DateTime object which seems to be able to be persisted and flushed to one column, but not the other.

I have checked the DB, the data isn't be written to the "protectiondate" column.

$lifecycle->setRemovalDate($extendedProtectionDate); // this line works
$lifecycle->setProtectionDate($extendedProtectionDate); // this line doesn't
$em = $this->doctrine->getManager();
$em->persist($lifecycle);
$em->flush();

The fields are defined identically:

    /**
     * @var DateTime
     *
     * @ORM\Column(name="removalDate", type="date", nullable=true)
     */
    private $removalDate;

    /**
     * @var DateTime
     *
     * @ORM\Column(name="protectionDate", type="date", nullable=true)
     */
    private $protectionDate;

As are the accessors and mutators:

   /**
     * @param DateTime|null $removalDate
     *
     * @return Lifecycle
     */
    public function setRemovalDate($removalDate = null) : self
    {
        $this->removalDate = $removalDate;

        return $this;
    }

    /**
     * @return DateTime|null
     */
    public function getRemovalDate() : ?DateTime
    {
        return $this->removalDate;
    }

    /**
     * @param DateTime|null $protectionDate
     *
     * @return Lifecycle
     */
    public function setProtectionDate($protectionDate = null) : self
    {
        $this->protectionDate = $protectionDate;

        return $this;
    }

    /**
     * @return DateTime|null
     */
    public function getProtectionDate() : ?DateTime
    {
        return $this->protectionDate;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文