首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >禁用来自yml的相关对象id的自动索引

禁用来自yml的相关对象id的自动索引
EN

Stack Overflow用户
提问于 2011-01-06 18:41:06
回答 1查看 451关注 0票数 0

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

例如

用户: id,名称

消息: id,sender_id,receiver_id,消息

如果我定义消息和用户之间关系,消息只有一个发送者和接收者,则当我从模型生成sender_id时,sql将自动索引receiver_id和SQL域。我想禁用发送者的索引,因为我用sender_id和接收者id一起手动创建了索引。如何禁用自动生成的索引?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-09 22:41:05

你好,我以为你在用MySQL,然后看了一下Doctrine/Export/Mysql.php,我找到了这个:

代码语言:javascript
复制
// 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()));    
             }   
         }   
     }   
 }   

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4614031

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档