Forum: Ruby on Rails How do you check if associated table is empty from find?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2c2f3ce7125411ff78a1d3e902aa2a4d?d=identicon&s=25 Bob Sanders (adistarmid)
on 2009-02-17 02:36
So I have two tables:

- teams
- players

I'm trying to find all teams that have no players. I thought this could

Team.find(:all, :joins => :players, :conditions => ["players.size = ?",
0] )

Of course that's not working for me because I'm mixing the SQL with
Rails. Do you know the proper way to find all teams that have no
D69d23d8e811e8ab2a8593380d6ede63?d=identicon&s=25 Jeff Emminger (jemminger)
on 2009-02-17 02:47
(Received via mailing list)
You could add a :counter_cache to your model if you want a simple

On Feb 16, 8:36 pm, Bob Sanders <>
This topic is locked and can not be replied to.