How to describe negative find condition in has_many

I have a Teams that has_many Players.

I need to get the list of Teams that have no active players (whether
they have 0 players or they have a lot of players all of whom are non-

Can’t figure out the conditions for doing this other than subtracting
the ones with active players from the list of all teams. The issue is
that I don’t want teams with some non-active players, I need the
teams which have only non-active players.

Here’s how I’m doing it now. I assume that there’s a better way so
will appreciate seeing the magic.



Player < AR::Base

validates_inclusion_of :status, :in =>
[:active, :inactive, :injured, :dead]


Team < AR::Base

has_many :players

named_scope :with_active_players, {
:include => :players,
:conditions => [“players.status = ?”, “active”],
:group => “”, # no dups
:order => ‘’

def self.without_active_players
(Team.find(:all) - Team.with_active_players).sort_by { |t| }



named_scope :without_active_players, :conditions => “NOT EXISTS(SELECT *
FROM players WHERE AND status=‘active’)”, :order =>

Does this work?


2010/2/14 cpr [email protected]

He shoots. He scores!

Thanks much for the insight.