What happens if you just leave the :source part out? I've never had to use 
that.

Op dinsdag 29 juli 2008 20:00:23 UTC+2 schreef mfairchi het volgende:
>
> 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:in `check_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:in `new' 
>         from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/ 
> active_record/associations.rb:1128:in `songs' 
>         from (irb):7 
> >> pl.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

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/UUnbaJZFDjQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to