doucandiao9180 2012-10-12 16:31 采纳率: 100%
浏览 81
已采纳

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

I have a CGridView widget in my "PointMutationsVarscan" model set up to search a numeric non-pk value in a related model, called "GeneExpressionCufflinksGene"

I declare the search var within the PointMutationsVarscan model in the usual way to disambiguate:

public $patient_gecg_search;

Search rule in PointMutationsVarscan contains search var:

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:

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

The the CGridView widget in the PointMutationsVarscan view:

$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.

fpkm is a double precision float in the database. I can use comparison operators on fpkm just fine within the GeneExpressionCufflinksGene model's own CGridView widget. Comparison operators only fail when searching as a relation through the PointMutationsVarscan model.

Thanks for any insight you might have on this.

  • 写回答

1条回答 默认 最新

  • dtbam62840 2012-10-12 18:31
    关注

    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. 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. Obviously there's something I'm not understanding but regardless, numeric comparisons now return the proper results.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重