query fields conditions cake all sorting cakephp paginator

sorting - fields - CakePHP-paginar y ordenar hasMany asociación



list cakephp (1)

Tengo tres tablas:

Libro -> pertenencia A -> Documento, Documento -> hasOne -> Libro, Documento -> hasMany -> Idioma, Idioma -> pertenencia A -> Documento

Document.php

public $hasOne = array( ''Book'' => array( ''className'' => ''Book'', ''foreignKey'' => ''document_id'', ''dependent''=>true, ) public $hasMany = array( ''Language'' => array( ''className'' => ''Language'', ''foreignKey'' => ''document_id'' )

Book.php

public $belongsTo = array( ''Document'' => array( ''className'' => ''Document'', ''foreignKey'' => ''document_id'' ) );

Language.php

public $belongsTo = array( ''Document'' => array( ''className'' => ''Document'', ''foreignKey'' => ''document_id'' ) );

BooksController.php

$this->Book->bindModel(array( ''hasOne'' => array( ''Language'' => array( ''foreignKey'' => false, ''conditions'' => array(''Document.id = Language.document_id'') )); $this->Prg->commonProcess(); $this->Paginator->settings = [ ''conditions'' => $this->Book->parseCriteria($this->Prg->parsedParams()), ''contain'' => array(''Document'',''Language'') ]; $this->set(''books'', $this->Paginator->paginate());

index.php

<th><?php echo $this->Paginator->sort(''Document.Language.type'',__(''language'')); ?></th>

¡Simplemente no puedo ordenar los datos por tipo de idioma!

¿Alguien puede sugerir una solución para este problema?


Puede usar la función de campo virtual para ordenar por tipo de idioma.

Primero, agregue este campo virtual a su modelo de documento:

public $virtualFields = [''Min_LangType'' => ''SELECT MIN(type) FROM languages as Language WHERE Language.document_id = Document.id''];

Luego, ordena por tipo de idioma de esta manera:

$this->Paginator->sort(''Document.Min_LangType'',__(''language''));