Accessing data in a join table with the related models

Comparing #6 with #7

Revision #7 was created by erikj erikj on Jul 15, 2012, 12:39:42 PM.

Changing "moviesJoin" to "watched" since "moviesJoin" is not defined anywhere, making the script not work.

Content

[...]
...
public function relations() {
return array(
'watched' => array(self::HAS_MANY, 'ViewerWatchedMovie', 'viewer_id'),
'movies' => array(self::HAS_MANY, 'Movie', 'movie_id',
'through' => '
moviesJoinwatched'),
...
```
[...]
To make it eager: `Viewer::model()->with('watched', 'movies')->findByPk($id)`.

I have it on [good authority](http://www.yiiframework.com/forum/index.php?/topic/8581-selecting-join-table-with-mant-to-many/page__st__40__p__123710__hl__creocoder#entry123710 "forum link") that the coherence of indexes of the two arrays `$viewer->
moviesJoinwatched` and `$viewer->movies` is assured. But this fact (feature?) is not documented so it makes me nervous. That's why I prefer a variation.

Add a relation to the `ViewerWatchedMovie` model:

```php
class ViewerWatchedMovie extends CActiveRecord {
[...]