gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:46:18 24 4
gpt4 key购买 nike

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/

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