When To Use Modelname() And Modelname::model()? In Activerecord

Hello,

Is there any noticeable difference using Model() and Model::name()?

Which is the difference? I’m used to be using Model::model() when making find queries. When making other create, edit or delete operations I always use only the model name - Model().

Am I doing it right?

Maybe I did not get the right point.

When you use modelname::model(), it will use a class.

If you can use model() directly, then means your model code contains below static function:




	/**

	 * Returns the static model of the specified AR class.

	 * Please note that you should have this exact method in all your CActiveRecord descendants!

	 * @param string $className active record class name.

	 * @return SrmBid the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}



Yeah, but why should I use one or another?

Do you have any pratical example of using both?

When you call Modelname::model() you get an instance of a Modelname that does not represent any particular record in the database. It should be used to call pseudo-static methods, like the find* family, called class-level methods in Yii.

Every other instance, either create by the new operator or returned by the find* methods family, represent a specific record. Static methods like find* should not be called from them.

The distinction is not clear. This has been introduced to avoid limitations of real static methods and/or properties.