douye6812 2016-03-06 11:29
浏览 45
已采纳

Yii按关系列HAS_MANY排序

Business model:

One invoice can have can have multiple status (Draft, in progress, send, deleted).

In CGridView I want display invoices with last status

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'carriage-grid',
    'dataProvider'=>$model->search(array(
        'completed'=>true,
        'pagination'=>true,
    )),
    'filter'=>$model,
    'columns'=> [
        array(
        'name'=>'InvoiceName',
        'type'=>'raw',
        'value'=>$model->InvoiceName,
    ),
        array(
        'name' => 'InvoiceStatus',
        'value' => $model->InvoiceStatus->Name,
    ),
    ]
)); ?>

In invoice model I have declared relation:

'status'=>array(self::HAS_MANY, 'InvoiceStatus', 'invoice_id'),

In CGridView data displayed is correct, but when I try to order by InvoiceStatus->name

What I get:

(BY ASC)
  1. Invoice name + first status
  2. Invoice name 2 + first status

(BY DESC)

  1. Invoice name + last status
  2. Invoice name 2 + last status

What I expect to get:

(BY ASC)

  1. Invoice name + A status
  2. Invoice name 2 + B status

(BY DESC)

  1. Invoice name 2 + B status
  2. Invoice name 1 + A status

That mean, that I want order all record not only status, and always display last status

展开全部

  • 写回答

1条回答 默认 最新

编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部