2017-04-19 36 views
0

我有這個安裝在我的表類入門CakePHP中3.x的相關數據

Icases表

$this->table('icases'); 
$this->displayField('name'); 
$this->primaryKey('id'); 

$this->belongsTo('Clients', [ 
    'foreignKey' => 'client_id' 
]); 
$this->hasMany('Documents', [ 
    'foreignKey' => 'icase_id' 
]); 
$this->belongsToMany('Users', [ 
    'foreignKey' => 'icase_id', 
    'targetForeignKey' => 'user_id', 
    'joinTable' => 'icases_users' 
    ]); 

客戶表

$this->table('clients'); 
$this->displayField('name'); 
$this->primaryKey('id'); 

$this->hasMany('Icases', [ 
    'foreignKey' => 'client_id' 
]); 
$this->belongsToMany('Users', [ 
    'foreignKey' => 'client_id', 
    'targetForeignKey' => 'user_id', 
    'joinTable' => 'clients_users' 
    ]); 

IcasesUsers表

$this->table('icases_users'); 
$this->displayField('icase_id'); 
$this->primaryKey(['icase_id', 'user_id']); 

$this->belongsTo('Icases', [ 
    'foreignKey' => 'icase_id', 
    'joinType' => 'INNER' 
]); 
$this->belongsTo('Users', [ 
    'foreignKey' => 'user_id', 
    'joinType' => 'INNER' 
    ]); 

在Icases表我有這樣的SQL,它檢索相關的客戶,誰是在登錄的用戶有效的和未決案件數據。這工作得很好,直到用戶設置過濾器,包括歸檔的案例以及積極和待批的這返回107077行,並且出現內存錯誤。 有沒有辦法使用contains()寫這個sql,並在將數據提供給用戶之前以塊的形式獲取數據,以便跨越內存限制?

$cases_data = TableRegistry::get('icases')->find('all') 
       ->select(['icases.id', 'icases.state', 'icases.client_id', 'icases.name', 'icases.age', 'clients.name']) 
       ->innerJoin('icases_users', 'icases_users.icase_id = icases.id') 
       ->where($conditions) 
       ->innerJoin('clients', 'clients.id = icases.client_id') 
       ->group(['icases.id']) 
       ->order(['clients.name' => 'ASC', 'icases.name' => 'ASC']) 
       ->execute() 
       ->fetchAll('assoc'); 

回答

0

你可以分頁你的結果。

請參閱Paginator HelperPagination Component文檔。

+0

嗨Rayann你可以給我例子,如果在Table類中使用這個Paginator helper請。因爲這個文件對我沒有任何意義。 –

+1

您還需要查看[分頁組件]的文檔(https://book.cakephp.org/3.0/en/controllers/components/pagination.html)。 –