禁用 yml 中相关对象 ID 的自动索引

发布于 2024-10-11 00:01:07 字数 261 浏览 3 评论 0原文

Doctrine 自动在用于定义对象关系的列上创建索引,

例如

user: id, name

message: id, sender_id,receiver_id, message

如果我以消息有一个发送者和一个接收者的方式定义消息和用户之间的关系,当我从模型生成sql时,学说将自动索引sender_id和receiver_id字段。我想禁用发送者上的索引,因为我使用发送者 ID 和接收者 ID 一起手动创建索引。如何禁用自动生成的索引?

Doctrine Automatically creates indexes on columns that are used to define object relations,

For example

user: id, name

message: id, sender_id, receiver_id, message

if I define relationship between message and user in a way that message has one Sender and has one Receiver, doctrine will automatically index sender_id and receiver_id fields when I generate sql from model. I would like to disable index on sender, because I manually create index with sender_id and receiver id together. How can I disable auto generated index?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤感在游骋 2024-10-18 00:01:07

你好,我假设你使用的是 MySQL,并查看了 Doctrine/Export/Mysql.php
我发现:

// build indexes for all foreign key fields (needed in MySQL!!)
if (isset($options['foreignKeys'])) {
      foreach ($options['foreignKeys'] as $fk) {
          $local = $fk['local'];
          $found = false;
          if (isset($options['indexes'])) {
             foreach ($options['indexes'] as $definition) {
                 if (is_string($definition['fields'])) {
                     // Check if index already exists on the column                            
                   $found = $found || ($local == $definition['fields']);    
                 } else if (in_array($local, $definition['fields']) && count($definition['fields']) === 1) {
                    // Index already exists on the column
                    $found = true;
                 }   
            }   
        }   
        if (isset($options['primary']) && !empty($options['primary']) &&
                in_array($local, $options['primary'])) {
             // field is part of the PK and therefore already indexed
             $found = true;
        }   

        if ( ! $found) {
            if (is_array($local)) {
             foreach($local as $localidx) {
                 $options['indexes'][$localidx] = array('fields' => array($localidx => array()));
             }   
        } else {
              $options['indexes'][$local] = array('fields' => array($local => array()));    
             }   
         }   
     }   
 }   

如果我理解正确,禁用索引应该是主键的一部分。

Hello I assumed you were using MySQL, and took a look in Doctrine/Export/Mysql.php
I found this :

// build indexes for all foreign key fields (needed in MySQL!!)
if (isset($options['foreignKeys'])) {
      foreach ($options['foreignKeys'] as $fk) {
          $local = $fk['local'];
          $found = false;
          if (isset($options['indexes'])) {
             foreach ($options['indexes'] as $definition) {
                 if (is_string($definition['fields'])) {
                     // Check if index already exists on the column                            
                   $found = $found || ($local == $definition['fields']);    
                 } else if (in_array($local, $definition['fields']) && count($definition['fields']) === 1) {
                    // Index already exists on the column
                    $found = true;
                 }   
            }   
        }   
        if (isset($options['primary']) && !empty($options['primary']) &&
                in_array($local, $options['primary'])) {
             // field is part of the PK and therefore already indexed
             $found = true;
        }   

        if ( ! $found) {
            if (is_array($local)) {
             foreach($local as $localidx) {
                 $options['indexes'][$localidx] = array('fields' => array($localidx => array()));
             }   
        } else {
              $options['indexes'][$local] = array('fields' => array($local => array()));    
             }   
         }   
     }   
 }   

If I understand correctly, to disable the index should be part of the primary key.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文