douyun3887 2015-08-04 06:07
浏览 26
已采纳

CakePHP - 分页查询附加默认条件“TableName.deleted”!= 1“

I'm using Cakephp V2.0 and having huge application working on it. Below is the what issue i'm facing right now.

Issue: Select Query is what automatically set condition like "TableName.deleted" != 1

Which does the creating issue actually, i want to add my custom condition in this query to get all soft-deleted records i.e.: "TableName.deleted" == 1 . but when We are using $this->paginate() function, it will append default condition at the end of MySQL Query condition and then MySQL Query will look like this:

("TableName.deleted" == 1) AND "TableName.deleted" != 1 Order By xyz

So it's retrieving the record set only by taking last condition and return only records which are not deleted.

How do i remove this default CakePHP condition ("TableName.deleted" != 1)?

Edited(Added Code):

if (isset($this->passedArgs['showdeleted']) && $this->passedArgs['showdeleted'] == 1) {
            $displayConditions['AND']['tableName.deleted'] = "1";
        } else {
            $displayConditions['AND']['tableName.deleted'] = "0";
        }

        $this->paginate = array(
            'conditions' => $displayConditions,
            'fields' => $this->displayFields,
            'limit' => $show_page,
            'group' => 'tableName.id',
            'contain' => array(
                'tbl1',
                'tbl2',
                'tbl3',
                'tbl4',
                'tbl5',
            ),
        );

        $returnRecords = $this->paginate();

Can anyone please let me know what should i do to resolve this. any help would be appreciated!

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dousi1961 2015-08-05 08:24
    关注

    Thanks for your suggesting and comments.

    Actually i got the answer for the same. we have created behavior for the same

    SoftDeletableBehavior.php

    In which we have defined related methods which was appending the condition "TableName.deleted" != 1. and it was also mentioned in Model as well like below:

    var $actsAs = array(
            'SoftDeletable' => array(
                'field' => 'deleted',
                'find' => true
            ),
    
        );
    

    so i just made one very minor change and it's working.

    var $actsAs = array(
                'SoftDeletable' => array(
                    'field' => 'deleted',
                    'find' => false
                ),
    
            );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line