Could not find the association

Hey peeps,

I have the following models:

class Profile < ActiveRecord::Base
has_many :tracks, :through => :watcher
has_many :watchers
end

class Watcher < ActiveRecord::Base
belongs_to :profile
belongs_to :watchable, :polymorphic => true
end

class Track < ActiveRecord::Base
has_many :watchers, :as => :watchable, :dependent => :destroy
has_many :profiles, :through => :watchers
end

To explain things a bit more, a Profile can upload a Track. Other
Profiles can Watch this Track for new Comments. This all is working
fine, except for when I try to do something with a track in my Profile
model.
For instance (a track actually belongs to a user, which has a profile):

def test
tracks.each do |t|
t.user.profile
end
end

Then I get the error: Could not find the association :watcher in model
Track

Anybody any idea what might be wrong? I’d be more than happy to share
more code.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs