B
B
byms2016-03-18 12:31:42
MySQL
byms, 2016-03-18 12:31:42

How to do grouping with sorting in Yii query?

There is such a request, you need to sort the Catalog by the sort field and group

$models = Catalog::model()->with(array(
      'model' => array(
        'order'=>'t.sort ASC',
      ),
      'model.parent_model'=>array(
        'select'=>false,
        'condition'=>'model.parent=:parentId',
        'params'=>array(':parentId'=>$selectedModel->parent_model->id),
      ),
    ))->findAll(
      array(
        'condition'=>'gallery_photo_id=:galleryPhoto',
        'params'=>array(':galleryPhoto'=>$galleryPhoto->id),
        'order' => 't.sort ASC',
        'group' => 't.model_id'
      )
    );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Soldatov, 2016-03-18
@TPbIHTPABA

The selection also includes sorting and grouping. What exactly is the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question