I can''t seem to think straight this evening. I have the following models class Candidate < ActiveRecord::Base has_many :castings has_many :projects, :through => :castings end class Project < ActiveRecord::Base has_many :castings has_many :candidates, :through => :castings end class Casting < ActiveRecord::Base belongs_to :project belongs_to :candidate end I need to get a list of projects that the candidate has NO castings for. The opposite of candidate.projects. Any zen way to do it? Make it fit into a form.select ? --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
has_many :projects_uncasted_for, :class_name => ''Project'', :finder_sql => <<-''end'' select * from projects left join castings on projects.id castings.project_id where castings.candidate_id is null or castings.candidate_id !#{id} end On May 6, 3:23 am, Tomislav Filipčić <tomisl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I can''t seem to think straight this evening. I have the following > models > > class Candidate < ActiveRecord::Base > has_many :castings > has_many :projects, :through => :castings > end > > class Project < ActiveRecord::Base > has_many :castings > has_many :candidates, :through => :castings > end > > class Casting < ActiveRecord::Base > belongs_to :project > belongs_to :candidate > end > > I need to get a list of projects that the candidate has NO castings > for. The opposite of candidate.projects. Any zen way to do it? Make it > fit into a form.select ?--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On May 6, 6:07 am, eden li <eden...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> has_many :projects_uncasted_for, :class_name => ''Project'', :finder_sql > => <<-''end'' > select * > from projects left joincastingson projects.id =castings.project_id > wherecastings.candidate_id is null orcastings.candidate_id !> #{id} > endThanks Eden. I changed the query to select DISTINCT projects.* from projects left join castings on projects.id = castings.project_id where castings.candidate_id is null or castings.candidate_id != #{id} and now it seems works great. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---