What Is Difference Between Using Many_Many Relation Vs "through" With Has_Many

I was going through the wiki article http://www.yiiframework.com/wiki/385/displaying-sorting-and-filtering-hasmany-manymany-relations-in-cgridview/ and its source code in github https://github.com/yjeroen/ManyMany

Since i was having several MANY_MANY relations in my DB, i came across "through" in above article.

I im not able to understand, why author have used relation in model Gener.php as


'songs'  => array(self::MANY_MANY, 'Song', 'song_genre(genre_id, song_id)')

where as in Song.php as


'hasGenres' => array(self::HAS_MANY, 'SongGenre', 'song_id'),

'genres'=> array(self::HAS_MANY, 'Genre', 'genre_id', 'through'=>'hasGenres'),

why not used in Song.php like this :


'genres'=> array(self::MANY_MANY, 'Song', song_genre(song_id,gener_id)')

what is difference between these two? where should we use which? please help. Thanks

in MANY_MANY scenario you do not have access to pivot table (song_genre), so you cannot fetch any additional information from columns that could be placed there.