Select

I have 2 tables:

table 1: orders

columns: id, customername, time, amount

table 2: order_details

columns: id, order_id, product, quantity

this is my order_details model code:




public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

               'rel_orders' => array(self::BELONGS_TO,'orders','order_id'),

               

		);

	}


..........

public function show()

	{

         


          $criteria=new CDbCriteria;


          $criteria->select = 'od.order_id, od.sld';

          $criteria->alias = 'od';

          #$criteria->limit = 10;

          #$criteria->sort = $sort;


          $criteria->with = array('rel_orders' => array(

               'select' => 'rel_orders.time, , (now() - rel_orders.time) as elapsedtime',

               'alias' => 'o',

          ));




		$dataProvider = new CActiveDataProvider(get_class($this), array(

			'criteria'=>$criteria,

               'pagination'=>array(

                    'pageSize'=>20,

               ),

		));


          

          return $dataProvider;

	}




what is the correct way in getting the elapsed time? and display it on cgridview?

You can add a public $elapsedtime to your orders model. Then in CGridView add a column like:


array(

    'name'=>'Elapsed time',

    'value'=>'$data->rel_orders->elapsedtime',

    'type'=>'text',

),



Thanks Mike,

Im going to try this

Mike, any idea how to do this?

Thanks

What exactly? You know where your model file is, right? Just add


public $elapsedtime;



to that class.

Woh, I didn’t thought it would be this easy…

It is working now!

Thanks mike :slight_smile: