Skip to content

Instantly share code, notes, and snippets.

@thomasbiddle
Created January 12, 2013 02:28
Show Gist options
  • Save thomasbiddle/4515739 to your computer and use it in GitHub Desktop.
Save thomasbiddle/4515739 to your computer and use it in GitHub Desktop.
if model Foo has_many model Bars how can I find Foos that don't have any Bars at all?
Foo.all.each do |f|
if Bar.where(:foo_id => f.id).all.empty?
puts "#{f.id} has no bars!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment