简体   繁体   English

Yii CGridView BELONGS_TO关系搜索:数值比较运算符失败

[英]Yii CGridView BELONGS_TO relation search: Numeric comparison operator fails

I have a CGridView widget in my "PointMutationsVarscan" model set up to search a numeric non-pk value in a related model, called "GeneExpressionCufflinksGene" 我在“ PointMutationsVarscan”模型中设置了CGridView小部件,以在名为“ GeneExpressionCufflinksGene”的相关模型中搜索非pk数值

I declare the search var within the PointMutationsVarscan model in the usual way to disambiguate: 我用消除歧义的常用方法在PointMutationsVarscan模型中声明了搜索变量:

public $patient_gecg_search;

Search rule in PointMutationsVarscan contains search var: PointMutationsVarscan中的搜索规则包含搜索变量:

array('id, ... patient_gecg_search, geneExpressionCufflinksGene', 'safe', 'on'=>'search'),

Model relation: 模型关系:

'geneExpressionCufflinksGene' => array(self::BELONGS_TO,'GeneExpressionCufflinksGene',array('gene'=>'gene_id')),

Search function: 搜索功能:

public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id,true);
// yada yada

$criteria->with[] = 'geneExpressionCufflinksGene';          
if($this->patient_gecg_search) {
$criteria->compare( 'geneExpressionCufflinksGene.fpkm', $this->patient_gecg_search, true);          
$criteria->addSearchCondition("geneExpressionCufflinksGene.fpkm",$this->patient_gecg_search);
}
return new CActiveDataProvider($this, array(
    'criteria'=>$criteria,
        'sort'=>array(
        'attributes'=>array(
            'patient_search'=>array(
                'asc'=>'patient.id',
                'desc'=>'patient.id DESC',
            ),

            'patient_gecg_search'=>array(
                'asc'=>'geneExpressionCufflinksGene.fpkm',
                'desc'=>'geneExpressionCufflinksGene.fpkm DESC',
            ),
            '*',
        ),
        ),
));
}   

In the GeneExpressionCufflinksGene model rules, fpkm is a numeric value: 在GeneExpressionCufflinksGene模型规则中,fpkm是一个数值:

array('fpkm, fpkm_conf_lo, fpkm_conf_hi', 'numerical'),

The the CGridView widget in the PointMutationsVarscan view: PointMutationsVarscan视图中的CGridView小部件:

$criteria=new CDbCriteria;
$dataProvider=$model->search();
$dataProvider->pagination = array('pageSize' => 15);
$columns=array();
$columns[]= array(
        'name'  => 'patient_gecg_search',
        'value'=>'$data->geneExpressionCufflinksGene->fpkm', 
        'type'  => 'raw',
        'htmlOptions'=>array('style'=>'width:250px;'),
    ); 

$this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'point-mutations-varscan',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>$columns,
    )
);

Essentially the problem is that I can't do a numeric comparison search (> < = etc ) on this belongs to relation column. 本质上,问题在于我无法对此属于关系列的对象进行数字比较搜索(> <=等)。 It only does a string matching search. 它仅进行字符串匹配搜索。 For example if I search for 123, it will return all the numeric fpkm values that match 123, but if I do <123 or >1 it doesn't return any records, they way you'd expect for a local parameter. 例如,如果我搜索123,它将返回所有与123相匹配的数字fpkm值,但是如果我执行<123或> 1,则它不返回任何记录,它们会以您期望的本地参数的方式显示。

fpkm is a double precision float in the database. fpkm是数据库中的双精度浮点数。 I can use comparison operators on fpkm just fine within the GeneExpressionCufflinksGene model's own CGridView widget. 我可以在GeneExpressionCufflinksGene模型自己的CGridView小部件内对fpkm使用比较运算符。 Comparison operators only fail when searching as a relation through the PointMutationsVarscan model. 仅当通过PointMutationsVarscan模型作为关系搜索时,比较运算符才会失败。

Thanks for any insight you might have on this. 感谢您对此的任何见解。

And the solution ...... 解决方案......

$criteria->addSearchCondition("geneExpressionCufflinksGene.fpkm",$this->patient_gecg_search, $escape=true, $operator='OR');

I added the escape param and changed the operator to OR instead of default AND. 我添加了转义参数,并将运算符更改为OR而不是默认的AND。 My guess is it's also doing a string search in there somewhere and using the OR operator allows the comparison operation to occur in addition to the string comparison. 我的猜测是,它还在其中的某个位置进行字符串搜索,并且使用OR运算符还允许在进行字符串比较之外进行比较操作。 Obviously there's something I'm not understanding but regardless, numeric comparisons now return the proper results. 显然有些事情我不理解,但是无论如何,数值比较现在都能返回正确的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM