Validator and inherited object

Hi guys,

I have a problem and I am new to Yii so perhaps I am doing something completely ridiculous :P, but bear with me.

I have a structure like this

class object extends CActiveRecord{

  protected $object_type;

  public function rules(){

    return array('object_type', 'required');



class object_text extends object {

  protected $position;

  public function rules(){

    return array_merge(parent::rules(),array(





I use


to set attributes and when I print_r $text_object it seems to be a nice Active Record object with attributes filled in.

Now I would like to run a validator on it and save it.

When I try using $text_object->save(); I get validation errors like this:

Array ( [object_type] => Array ( [0] => Object Type cannot be blank. ) [position] => Array ([0] => Position can not be blank))

If I remove rules, it passes but wont save…

Now what is it that I am doing wrong?

I will add that my goal is to have one table object and say 2 models : text and image, with some properties and methods identical and some unique (which I suppose is a purpose of inheritance) [Optionally I am considering 2 tables but still same structure of classes - whichever will be easier/more proper].

Any thoughts?

Why are you doing by hand things that gii already do for you?

Does GI create classes with inheritance?

Besides if I do something by hand I will probably learn better how it works (given that I am new to Yii)

Tell us more about



Hi Tommy,

This is simply a method from CActiveRecord, unmodified.

Thank you :rolleyes:

You should tell us more about what information you pass to that method.

Also read this if you haven’t already.



Thanks for assistance. Problem solved. My downfall was in declaring those database fields as properties of my classes.

Lesson learned! :)