Good day! Understanding CActiveRecord Models As far as I understand, any CActiveRecord model is a wrapper over a table in the database. The findAll() method performs a query of the type:

 SELECT * FROM `table` `t` 

But, in practice, more complex queries are usually needed, which contain links to other tables. For example:

 SELECT p.*, c.title FROM post p LEFT JOIN category c ON c.id_cat = p.id_cat 

The question is whether it is possible to write such links in the model so that when they call findAll() they automatically build a complex SQL query.

    1 answer 1

    Yes you can. Links are specified in the public function relations () method. Then we make such a call.

     $posts=Post::model()->with('author','categories')->findAll(); 

    Where 'author', 'categories' are the names of the links. Generally we read here relational relations in CActiveRecords .