I have tried to implement the approach but am still getting some few problems.
I assumed the status in your sample code is the status field in the table tbl_order status.
In my Order model as follows:
public function scopes()
{
return array(
'newOrders'=>array(
'condition'=>"order_status.status=:thestatus",
'params'=> array(':thestatus' => 'New'),
where order_status is the named relation defined in that Order Model as follows
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(
'branches'=>array(self::BELONGS_TO,'Branches','branch_id'),
'staff'=>array(self::BELONGS_TO,'Staff','who_created'),
'order_items'=>array(self::HAS_MANY,'OrderItems','order_id'),
'order_status'=>array(self::HAS_MANY,'OrderStatus','order_id')
);
}
In my controller I did as follows (Just as you directed me)
$newOrders = Orders::model()->newOrders();
Var_dumping $newOrders returns an object type, without records.
Trying to use it in CGridView I get the following
CException
Orders and its behaviors do not have a method or closure named "getData".