Conditions on an Include (nuby on rails)

I’ve got a database schema that is an artist with many tour_dates. I’m
trying to grab the artist info and active tour dates at the same time.
Simple enough:

In the controller:
@artist = Artist.find(params[:id], :include => :tour_dates)

Now I want to include only the tour_dates that happen after the first of
the current month. This is what I tried:

@artist = Artist.find(params[:id], :include => :tour_dates.active_dates)

and added

def self.active_dates
:conditions => “date > now()”,
:order => “date”)

to the tour_date model, just to see if i could get tour_dates after
right now to display. It doesn’t work quite the way I’d expect. How
would you do this? If you need to see more of my models or controllers
let me know.

I’m really just getting rolling on this so any help is appreciated.
I’ve got some books, I just didn’t see anything like this in them.

I also am grabbing
@artists = Artist.active_artists (similar model to the above) for a menu
on the page, which I realize may be redundant, but I can’t figure out
how to grab all the artist names and ids, but also everything for one
specific artist.


you would probably want to do this in yout Artist model
def active_dates
tour_dates.find(:all, :conditions => “date >
now()”, :order=>‘dates’)

or with an eager load(@artist =
Artist.find :all, :include=>:tour_dates) (no attributes here
on :tour_dates)

def active_dates {|date| d >now()}


On 8 fév, 07:23, Michael B. [email protected]