Single Model For Multiple Tables

is there a way to create a model that will gather data from several tables?

maybe, joined by sql, or by means of relations.

i want my CGridView and other widgets to operate with columns from joined tables as if they are in a single table.

How your tables are related to each other?

If you are storing their relation in a table then create model of that table and then Use this table to list the its and related data

table : post

table : users

table : category

table : user_post_cat_relation

if you have a model of user_post_cat_relation then you can use it to display records in CGridview

I don’t know if you cna but I don^t think it is a good solition.

Ifn your grid view you can have value for several models :

in your model :

public function relations() {

        // NOTE: you may need to adjust the relation name and the related

        // class name for the relations automatically generated below.

        return array(

            'projetsActif' => array(self::BELONGS_TO, 'TProjets', 'fk_projet'),

            'tachesActif' => array(self::BELONGS_TO, 'TTaches', 'fk_tache'),

            'personnesActif' => array(self::BELONGS_TO, 'TPersonnes', 'fk_personne'),



you can define relation and after use in your grid view :


            'name' => 'tachesActif',

            'value' => '$data->tachesActif->titre',

            'header' => 'Taches',


in you don’t want do that you can use a view define in your database.

the relations are sort of complicated.

so, there is no single table to completely connect all others.

can you give a little more information?

maybe, some links to read on the issue

or some explanations?

there is not too much info about it

In the model of User_post_cat_relation you can follow the rule describe here

I would highly recommend you read the blog tutorial

here is the guide link to related objects otherwise