Skip to content

Instantly share code, notes, and snippets.

@bernerdschaefer
Created February 1, 2011 20:15
Show Gist options
  • Save bernerdschaefer/806572 to your computer and use it in GitHub Desktop.
Save bernerdschaefer/806572 to your computer and use it in GitHub Desktop.
class Notification
property :name, String
belongs_to :user
end
class User
has n, :notifications
end
# Find all users with no notifications
User.all(:notifications => nil)
# Find all users with no notifications w/ a particular name?
# This doesn't work as expected, because "notifications.name" will
# be turned into an inner join, making the :notifications => nil condition
# moot.
User.all(:notifications => nil, "notifications.name" => "SomeName")
# Is this the only way to accomplish this?
User.has n, :some_name_notifications, :name => "SomeName"
User.all(:some_name_notifications => nil)
@xaviershay
Copy link

# Totally untested
User.all - User.all('notifications.name' => 'SomeName')
User.all(:notifications => {:name.not => "SomeName")) & User.all(:notification => nil)

This type of "negative" query generally sucks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment