Nesting Of Cactiverecord


class SomeModel extends CActiveRecord

{

    public static function model($className=__CLASS__)

    {

        return parent::model($className);

    }


    public function tableName()

    {

        return '{{some_table}}';

    }   


    public function getItemByParentId($parentId)

    {

        $criteria=new CDbCriteria;

        //some criteria


        return self::model()->findAll($criteria);

    }

}

This method works properly when I call it from controller


SomeModel::model()->getItemByParentId($someVariable)

But now I have 3 very similar to SomeModel models, so I want to put common methods to one class


class CommonModel extends CActiveRecord

{

    public static function model($className=__CLASS__)

    {

        return parent::model($className);

    }


    public function getItemByParentId($parentId)

    {

        $criteria=new CDbCriteria;

        //some criteria


        return self::model()->findAll($criteria);

    }

}


class FirstModel extends CommonModel

{

    public static function model($className=__CLASS__)

    {

        return parent::model($className);

    }


    public function tableName()

    {

        return '{{first_table}}';

    }

}


class SecondModel extends CommonModel

{

    public static function model($className=__CLASS__)

    {

        return parent::model($className);

    }


    public function tableName()

    {

        return '{{second_table}}';

    }

}

But get error

What is wrong?

self::model() refers to the SomeModel class. Use static::model() or $this->findAll().

Why do you do that?:huh:

Yes, thanks!

What?

Nested CActiveRecords?

Instead of that, you can use some file classes.