ruby on rails – return objects with no associated data – Education Career Blog

class Game < Event  
  has_many :statistics, :dependent => :destroy

  ...
end

class Statistic < ActiveRecord::Base
  belongs_to :game
end

I want to make a named scope that only returns games that have no statistics.

Thanks

,

Try

named_scope :no_statistics, :include => :statistics, :conditions => 'statistics.id IS NULL'

Leave a Comment