Hello,
I’ve used has_many :through many times with success but for
somereason am being stymied this time. Perhaps someone else can see
what I am not.
The three relevant models are these:
class Playlist < ActiveRecord::Base
has_many :songs, :through => ‘playlist_songs’, :source=>:song
has_many :playlist_songs
end
class PlaylistSong < ActiveRecord::Base
set_table_name ‘playlist_songs’
belongs_to :playlist
belongs_to :song
end
class Song < ActiveRecord::Base
has_many :playlists, :trhough=>‘playlist_songs’
end
when I try and use Playlist.songs i get an error, demonstrated below,
pl=Playlist.find :first
=> #<Playlist id: 1, name: “stimbletunes”, updated_at: “2008-07-28
16:38:10”, description: nil, created_at: “2008-07-28 16:38:10”>pl.songs
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find
the association “playlist_song” in model Playlist
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/reflection.rb:195:incheck_validity!' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/ active_record/associations/has_many_through_association.rb:5:in
initialize’
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/associations.rb:1128:innew' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/ active_record/associations.rb:1128:in
songs’
from (irb):7pl.songs.new
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find
the association “playlist_song” in model Playlist
If anyboday has an idea what I should do differently, please let me
know.
Thanks,
Michael Fairchild