// Define a model class for a table named 'users' class User extends CActiveRecord { public function tableName() { return 'users'; } } // Query the 'users' table for all users with an age greater than or equal to 18 $users = User::model()->findAll('age >= :age', array(':age'=>18));
// Define a model class for a table named 'posts' class Post extends CActiveRecord { public function tableName() { return 'posts'; } public function relations() { return array( 'author' => array(self::BELONGS_TO, 'User', 'author_id'), ); } } // Query the 'posts' table and include the author information for each post $posts = Post::model()->with('author')->findAll();In this example, we define a model class for a table named 'posts' and include a one-to-one relationship with a 'User' model. This allows us to easily query the posts table and include the author information for each post. Package Library: Yii Framework.