简体   繁体   English

教义注释上的枚举类型问题

[英]Issue with enum type on doctrine's annotations

I use doctrine entity's annotation to generate and update my schema and i have an issue with enum field 我使用原则实体的注释来生成和更新我的架构,但是枚举字段有问题

Here is my entity 这是我的实体

My User class : 我的用户类别:

<?php

namespace Schematify\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="users")
 */
class User 
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     * @var int
     */
    protected $id;

    /** @ORM\Column(length=250) */
    protected $email = '';

    /** @ORM\Column(length=32,options={"default":""}) */
    protected $pasword = '';

    /** @ORM\Column(type="string", columnDefinition="ENUM('visible', 'invisible')") */
    protected $status = '';


}

I developped a cli command named console.php in order to call all schema-tool update. 我开发了一个名为console.php的cli命令,以调用所有架构工具更新。 When i type php console.php orm:schema-tool:update --force there's always 1 query to execute : 当我输入php console.php orm:schema-tool:update --force ,总是有1个查询要执行:

ALTER TABLE users CHANGE status status ENUM('visible', 'invisible');

I use a mysql database and all my code is available here : https://github.com/talkspiritlab/schematify 我使用mysql数据库,所有代码都在这里提供: https : //github.com/talkspiritlab/schematify

Thanks 谢谢

To have a proper support for enum, even in schema/migrations tools, you should implement a custom type for each enums, as described in the second solution in the official documentation . 为了即使在架构/迁移工具中也对枚举提供适当的支持,您应该为每个枚举实现自定义类型,如官方文档中第二种解决方案所述

In addition to that, don't forget to mark them as needing comments : 除此之外,别忘了将它们标记为需要注释

Type::addType($name, $class);
$platform->registerDoctrineTypeMapping($name, $name);
$platform->markDoctrineTypeCommented($name);

Unless if you are using a very new version of DBAL that include this commit , then you don't need to mark as needing comment. 除非您使用的是包含此commit的非常新的DBAL版本,否则您无需标记为需要注释。 At the time of writing that would be master (or the hypothetical future v2.6). 在撰写本文时,它将是主要的(或假设的未来v2.6)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM