# Re: Finding all records that don't have child

**URL:** <https://www.ruby-forum.com/t/re-finding-all-records-that-dont-have-child/184137>\
**Category:** Rails\
**Created:** [February 25, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/re-finding-all-records-that-dont-have-child/184137 "2010-02-25T16:54:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmcorp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ccd318/32.png) [@fmcorp](https://www.ruby-forum.com/u/fmcorp)\
**Post date:** [February 25, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/re-finding-all-records-that-dont-have-child/184137/1 "2010-02-25T16:54:13Z")

</div>

That is finding all B records that have no parent. I want to find all A  
records that have no child…

I’m thinking that the best/fastest way to do this would to just use  
counters.

You wrote:

I would use a named\_scope in this instance, assuming the relationship  
fields are completely normal.

So the field that u want to check is the association id is nil.

an example for that would be like this:

named\_scope :unassociated, :conditions =\> “foreignkey\_id IS NULL”

hope that works…
