Difference between #7 and #8 of
Accessing data in a join table with the related models

Revision #8 has been created by krowe on Nov 13, 2012, 5:06:56 PM with the memo:

Fixed a few typos with the sample simple MANY_MANY relation.
« previous (#7)

Changes

Title unchanged

Accessing data in a join table with the related models

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

relations, active record, many_many, join table

Content changed

[...]
```php
class Viewer extends CActiveRecord {
...
public function relations() {
return array(
'movies' =>
 'movies' -> array(self::MANY_MANY, 'Movie', 'viewer_watched_movie(moviewer_id, movie_id)'),
...
```
[...]
echo $viewer . ' watched ' . $movie->title;
```
[This will perform poorly because it lazily loads `Movie`s one a
st a time in the loop. I can pep it up thus: `Viewer::model()->with('movies')->findByPk($id)`]

### The problem

How can I add the `liked` property to that `echo` in the loop? For example, is there a way to write relations and/or getters so I can write?:
[...]
16 1
30 followers
Viewed: 146 502 times
Version: 1.1
Category: How-tos
Written by: fsb
Last updated by: krowe
Created on: Dec 5, 2011
Last updated: 11 years ago
Update Article

Revisions

View all history