# Help me understand how to filter complex data

**URL:** <https://www.ruby-forum.com/t/help-me-understand-how-to-filter-complex-data/178968>\
**Category:** Rails\
**Created:** [November 14, 2009, 12:01pm UTC](https://www.ruby-forum.com/t/help-me-understand-how-to-filter-complex-data/178968 "2009-11-14T12:01:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![upisdown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/7ea924/32.png) [@upisdown](https://www.ruby-forum.com/u/upisdown)\
**Post date:** [November 14, 2009, 12:01pm UTC](https://www.ruby-forum.com/t/help-me-understand-how-to-filter-complex-data/178968/1 "2009-11-14T12:01:57Z")

</div>

So I am working on this project but I am having trouble with a find  
statement. My code is mostly working but it falls apart when more  
entries are added.

I am working on a submission manager. I want a table of submissions  
for editors of a specific genre for which they haven’t commented. When  
they comment I want it removed from table so that only the submissions  
they need to work on are showing. I tried two methods that produce the  
same results. One I used a find statement and another I tried a named  
scope. Right now I can filter out the submissions of the specific  
genre and then remove ones that have been commented on but soon as a  
second editor comments on them they show up again.

Here is my code for the named scope

(In the submission model)

named\_scope :not\_commented\_by, lambda { |u| { :include  
=\> :comments, :conditions =\> [‘comments.editor\_id != ? OR comments.id  
IS NULL’, u.id] } }

(In the User Controller)

@prose = Genre.find\_by\_name(‘Prose’).submissions.not\_commented\_by  
(@user)

Here is my code for the find statement

(In the user controller)

@prose = Genre.find\_by\_name(‘Prose’).submissions.find(:all, :include  
=\> :comments, :conditions =\> [‘comments.editor\_id != ? OR comments.id  
IS NULL’, @user.id])

Can anyone explain why this would stop working when a second comment  
is made? Anyone have suggestions for implementing this better?

Thank you for your time,  
Christian

---

<div class="post-metadata">

**Author:** ![upisdown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/7ea924/32.png) [@upisdown](https://www.ruby-forum.com/u/upisdown)\
**Post date:** [November 16, 2009, 6:18pm UTC](https://www.ruby-forum.com/t/help-me-understand-how-to-filter-complex-data/178968/2 "2009-11-16T18:18:20Z")

</div>

> @prose = Genre.find\_by\_name(‘Prose’).submissions.find(:all, :include  
> =\> :comments, :conditions =\> [‘comments.editor\_id != ? OR comments.id  
> IS NULL’, @user.id])
> 
> Can anyone explain why this would stop working when a second comment  
> is made? Anyone have suggestions for implementing this better?

Hmm… when a second person comments on a particular piece of prose  
that @user already commented on, then there will be a comments record  
where comments.editor\_id != @user.id, meeting one of your two OR  
conditions
