I have 3 models with a has_many through association:

class Recording
  has_many :listenings
  has_many :listeners, :through => :listenings, :source => :user
  ...
end

class User
  has_many :listenings, :foreign_key => "listener_id"
  has_many :listened_recordings, :foreign_key =>
"listener_id", :through => :listenings, :source => :recording
  ...
end

class Listening
  belongs_to :recording
  belongs_to :listener, :class_name => "User"
  ...
end

So I can get the recordings the user has listened to, easily with:

user.listened_recordings

How do create a find method that retrieves all of the recordings the
user has not listened to?
The way I have been doing it is:

Recording.all.reject { |r| listened_recordings.include?(r) }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
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