doctrine - 如何强制 "hint"实体字段应在 yaml 中建立索引?

标签 doctrine doctrine-orm yaml

Doctrine 2 中是否有任何方法可以提示在自动生成数据库时应该对列建立索引?我有一个线程实体:

Entities\Thread:
  type: entity
  table: Thread
  repositoryClass: Repositories\ThreadRepository
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    type:
      type: enumthreadtype
    code:
      type: string
      length: 10
      nullable: true
  manyToOne:
    group:
      targetEntity: Group
      inversedBy: threads
  oneToMany:
    messages:
      targetEntity: Message
      mappedBy: thread
    attachments:
      targetEntity: ThreadAttachment
      mappedBy: thread

通常通过“代码”(10 个字符的随机字符串)而不是 ID 来搜索线程。有没有办法表明应该使用 yaml 创建索引,或者我只需要在创建表后在数据库中执行此操作?

最佳答案

我在yaml中找不到这方面的文档,但是在阅读Doctrine\ORM\Mapping\ClassMetadatainfo之后我发现它如下

如果你想索引你的代码字段,你的 yaml 映射将是

Entities\Thread:
  type: entity
  table: Thread
  indexes:
      # _idx as suffix...
      thread_code_idx:
          columns: [ code ]
      # We can specify multiple indexes 
      another_idx
          # we can specify multiple columns for compound indexes
          columns [ type, code ] 
  repositoryClass: Repositories\ThreadRepository
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    type:
      type: enumthreadtype
    code:
      type: string
      length: 10
      nullable: true
  manyToOne:
    group:
      targetEntity: Group
      inversedBy: threads
  oneToMany:
    messages:
      targetEntity: Message
      mappedBy: thread
    attachments:
      targetEntity: ThreadAttachment
      mappedBy: thread

关于doctrine - 如何强制 "hint"实体字段应在 yaml 中建立索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8016686/

相关文章:

google-chrome - Chrome 加载一个 text/html 文件,但显示状态 "failed"并且不会在屏幕上呈现

php - Doctrine2,按多对多属性的计数获取实体顺序

php - 使用 Doctrine 查询生成器获取所有订购的实体

symfony - 弃用 : Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated

php - 在 Doctrine 中过滤 @OneToMany

php - 从请求填充实体的更好方法?

r - 将数据帧写入 yaml R

docker - Docker运行Kubernetes部署Yaml

java - 解析 Yaml 文件时出错 - 无法为 JavaBean 创建属性

php - Symfony3 可捕获 fatal error : Argument 1 passed to Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider