How can I use a derived Model with criteria on columns that don't exist

Hi guys,

I have a Model let’s say:


class A{

 public $site_no;

}

and I want to have a derived Model:


class B extends A{

 public $site_count;

}

Now I want to run in the Model B to a search() through CDbCriteria by doing:


$criteria->select = array('COUNT(site_no) AS site_count');

My CActiveDataProvider doesn’t return the Model B with ‘site_count’. It still gives the attributes back from the Model A.

How can I use $criteria->select with column aliases? Basically how can I use a derived Model B, whose attributes are completely derived attributes from Model A. The derived formulas are complicated, so I can’t just do a afterFind() on the attributes after I retrieved the data.

Have you overridden the model() method in your derived class?




	/**

	 * Returns the static model of the specified AR class.

	 * @return X the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}



No I haven’t. What should it be like?

Exactly like I posted. ::)

Oh that’s what you meant lol

Yes I had that already.

So I have figured out a solution. I’ve created a new model with the desired derived columns and extend from the parent class.

I had then to adjust some of the methods like rules and relations so it retrieves the rules and relations from the parent.