Alex Treber wrote:
Is it possible to use one result set in another query..
This is a kinda bogus example, but here goes
If a function returns a list of authors @authorList = getAllAuthorsBetween(2000,2004)
then I wanted to get what car they are driving @carList = getCarsDrivenBy(@authorList)
How can I write a query to do this?
def getCarsDrivenBy(list) Car.find(:all, :conditions => [" driver = ?", list]) end
This will do what you're looking for:
@people = Person.find(:all) def cars_driven_by(people) Car.find(:all, :conditions => ["driver_id IN (?)", people.map(&:id)]) end
people.map(&:id) will make an array of the IDs for the people.
Dan Manges