ActiveRecord relations

Hi,

Was ActiveRecord relations build for allowing you to save / updating two models in one go?

Also was ActiveRecord relations built for allowing you to use two models in one form and then saving them?

I understand there are many ways to do these tasks, but I am asking was this the "real" purpose of ActiveRecord relations?

Active Record links database tables into OO methodology by wrapping a table into a class. See what Wikipedia has to say.

The whole point of AR relations is when you can do this:




$model = Issue::model()->with(array('comments' => array(

'with' => 'author')))->findbyPk((int)$id);



Then you can just:




foreach($model->comments as $comment) {

echo $comment->subject . '<br/>';

echo $comment->content . '<br/>';

echo $comment->author->username;

...

}



Actually, the above is known as eager loading.

You can do the same thing just by doing this:




$model = Issue::model()->findbyPk((int)$id);



Yii will lazy load related records.