Model inheritance?

Hi guys,

I find it that I have a trouble wrapping my mind around mirroring my db’s inheritance structure.

I have three tables (simplified for the sake of this post):


CREATE TABLE object (

 object_id INT,

 common_option_1 VARCHAR(64),

 common_option_2 INT,

 common_option_3 TEXT,

 PRIMARY KEY (object_id)

);


CREATE TABLE image_object (

 object_id INT,

 image_option_1 TEXT,

 PRIMARY KEY (object_id),

  CONSTRAINT fk_image_object_object1

    FOREIGN KEY (object_id )

    REFERENCES object (object_id)

    ON DELETE CASCADE

    ON UPDATE CASCADE

);


CREATE TABLE group_object (

 object_id INT,

 group_option_1 INT,

 PRIMARY KEY (object_id),

  CONSTRAINT fk_group_object_object1

    FOREIGN KEY (object_id )

    REFERENCES object (object_id)

    ON DELETE CASCADE

    ON UPDATE CASCADE

);


CREATE TABLE text_object (

 object_id INT,

 text_option_1 VARCHAR(128),

 PRIMARY KEY (object_id),

  CONSTRAINT fk_text_object_object1

    FOREIGN KEY (object_id )

    REFERENCES object (object_id)

    ON DELETE CASCADE

    ON UPDATE CASCADE

);

So all in all, I keep common things in object, while specific options in respective tables. All linked in 1-1 relations.

Now I was thinking about how am I to mirror it in Yii’s models…

What I did initially was to simply create four models and then work on them in controllers and views e.g.:




public function actionEditTextObject($id){

[...]

  $text_object = TextObject::model()->findByPk($id);

  $object = Object::model()->findByPk($text_object->object_id);

[...]

  $this->render('edit',array(

     'text_object'=>$text_object,

     'object'=>$object

  ));

}



However I was thinking… am I doing it right? Perhaps I should simply extend text_object from object and work with one model? But how would I solve attributes’ assignments then? I mean as I understand the basic principle is 1 model per 1 data source… or am I wrong and this is more flexible than I imagine?

Please advise on the best course of action.

And if by any chance this issue was addressed before but I didn’t find the correct answer, simply point me to it.

Thanks in advance!

OK, my bad.

I suppose this post’s discussion answers my question (especially the answer I am sending to).

Sorry for unnecessary post.