I tried using the join you suggested ":joins => "LEFT OUTER
JOIN comments ON comments.submission_id = submissions.id AND
comments.user_id = #{u.id}" and even tried modifying it a bit to make it
work and it gives an error.

Specifically

Mysql::Error: Unknown column 'comments.user_id' in 'on clause'


I will try learning more about joins but it seems the issue is using
comments.user_id in the join will not work. I am not sure how to approach it
if this is the case.

Thanks.

On Sun, Nov 15, 2009 at 7:38 PM, Matt Jones <al2o...@gmail.com> wrote:

>
>
>
> On Nov 15, 12:56 am, christian <trimp...@gmail.com> wrote:
> > Thank you for your response and patience. I apologize for the double post
> > but I thought since I forgot the [Rails] tag that my post was rejected.
> >
> >  named_scope :not_commented_by, lambda { |user| { :include=> :comments,
> > :conditions => ["(submissions.id = comments.submission_id AND
> > comments.editor_id != ?) OR comments.id IS NULL", [user.id]] } }
> >
> > I don't think this represents what you were trying to say:
> >
> > select submissions.* from submissions left outer join comments on
> > submissions.id = submission_id AND editor_id =1 where comments.id IS
> NULL;
> >
>
> Fred's pretty much nailed this one - apologies for leading you astray
> (that's what I get for writing untested SQL before morning coffee...).
>
> So for your example, the scope on Submission would be:
>
> named_scope :not_commented_by, lambda { |u| { :joins => "LEFT OUTER
> JOIN comments ON comments.submission_id = submissions.id AND
> comments.user_id = #{u.id}", :conditions => 'comments.id IS NULL' } }
>
> Hope this helps!
>
> --Matt Jones
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to