I’m building an application to view webcomics. I’ve got three models,
User, Comic and Page.
I’d like to build an association in my User model that will return all
the Comic records which have 1 or more children Pages.
In my User model I have
class User < ActiveRecord::Base
has_many :comics, :class_name => “Comic”, :foreign_key =>
“created_by”, :order => “last_updated DESC”, :dependent => :destroy
has_many :live_comics, :class_name => “Comic”, :foreign_key =>
“created_by”, :order => “last_updated DESC”, :conditions => [“live = 1
AND published_on <= ?”, Time.now]
Each comic has a publication date and a boolean “live” value. Right
now, the association user.live_comics returns the set of Comic rows
where “live” is true and “published_on” is in the past.
I don’t want “user.live_comics” to return Comics with 0 pages. Is there
a way I can create an association to do that?