2017-04-19 79 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)。 –