Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
模型处的cakephp力指数_Php_Cakephp_Indexing_Cakephp 1.3 - Fatal编程技术网

模型处的cakephp力指数

模型处的cakephp力指数,php,cakephp,indexing,cakephp-1.3,Php,Cakephp,Indexing,Cakephp 1.3,在模型中,我使用了使用“力指数”的查找方法。模型很好,但当我对find方法进行测试时,发生了SQL错误。 我使用测试/夹具并定义DB模式和数据。在测试/夹具中,我不知道如何定义索引。因此,用于测试的DB没有索引。 如果您能告诉我如何在测试/夹具中定义索引,那就太好了 在模型中 $this->Model->find('all', array( 'fields' => array('foo'), 'conditions' => array('foo' =&

在模型中,我使用了使用“力指数”的查找方法。模型很好,但当我对find方法进行测试时,发生了SQL错误。 我使用测试/夹具并定义DB模式和数据。在测试/夹具中,我不知道如何定义索引。因此,用于测试的DB没有索引。 如果您能告诉我如何在测试/夹具中定义索引,那就太好了

在模型中

$this->Model->find('all', array(
     'fields' => array('foo'),
     'conditions' => array('foo' => foo),
     'joins' => array('FORCE INDEX(foo)'),
);
在测试/夹具中

var $fields = array(
    'id' => ....
    'foo' => ....
    'created' => ....
    'modified' => ....
 );

我认为这将有助于你:

“1-创建我自己的数据源-(在我扩展dbmysql的情况下) 数据源有两个任务:

它重写读取方法并检查模型是否设置了useIndex字段

    if (!empty($model->useIndex)) { 
            $this->useIndex = $model->useIndex; 
    } 

    return parent::read($model, $queryData); 
它会覆盖renderStatement方法,如果设置了$model->useIndex字段,则在select语句中的表别名后添加其值

if (strtolower($type) == 'select' && !empty($this->useIndex)) { 
        $res = "SELECT {$fields} FROM {$table} {$alias} {$this->useIndex} {$joins} {$conditions} {$group} {$order} {$limit}"; 
} else { 
        $res = parent::renderStatement($type, $data); 
} 
$this->useIndex = null; 
return $res; 
2-设置模型字段,其中包含使用索引、强制索引或忽略索引的sql部分

控制器中的eg:

$this->Task->useIndex = 'IGNORE INDEX(ind_usr_id)'; 
$this->paginate = array( 
        'fields' => array('Task.id', 'Task.name','User.id', 'User.name'), 
        'order' => 'Task.id', 
        'limit' => 10 
); 
$this->paginate('Task'); 

谢谢你的回答。我在test.php中添加了“$this->Model->query('altertable-tbl-addindex(foo);”);”。它很好用!!谢谢@用户2270371如果此答案对您有效,请“接受”它以将您的问题标记为“已回答”