Hi *, I have an issue with a relation I'm not able to understand: I have 3 tables, a releases table, a tracks table and a release_tracks table. The release_tracks table has a release_id and a track_id. Release and Track models have both a has_many :through => :release_tracks association (has_many :releases and has_many :tracks). I'm just not able to make it work ... For example
>> r = Release.new => #<Release:0x3732258 @attributes={"title"=>nil, "inserted_at"=>nil, "mb_id"=>nil}, @new_record=true> >> r.tracks ActiveRecord::HasManyThroughAssociationNotFoundError: ActiveRecord::HasManyThroughAssociationNotFoundError from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/reflection.rb:169:in `check_validity!' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_through_association.rb:6:in `initialize' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations.rb:876:in `new' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations.rb:876:in `tracks' from (irb):48
>> t = Track.new => #<Track:0x372f918 @attributes={"artist_id"=>nil, "title"=>nil, "inserted_at"=>nil, "mb_id"=>nil, "position"=>nil, "duration"=>nil}, @new_record=true> >> r.tracks << t ActiveRecord::HasManyThroughAssociationNotFoundError: ActiveRecord::HasManyThroughAssociationNotFoundError from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/reflection.rb:169:in `check_validity!' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_through_association.rb:6:in `initialize' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations.rb:876:in `new' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations.rb:876:in `tracks' from (irb):50
class Release < ActiveRecord::Base
has_many :tracks, :through => :release_tracks
end
class Tracks < ActiveRecord::Base
has_many :releases, :through => :release_tracks
end
class ReleaseTracks < ActiveRecord::Base
belongs_to :release belongs_to :track
end
What's wrong here ? Is the ReleaseTracks model really needed ?
TIA, ngw Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com