Topic: scope requires join and present condition

Let's say my model looks like this

   * Guest
   * Ride (n:m)
   * Taxi

The rides have time_from/time_to attributes, so the association between Guest and Taxi is valid within a time frame. Now I want to create a scope in Guest that selects me only those guests that are currently riding in a taxi, which means that = true ...but only if is between ride.time_from and ride.time_to (or is >= ride.time_from and ride.time_to is null).
I think I can go the hard way and write a long SQL statement that does 2 joins manually. But since I've defined the relationship already (guest has_many taxis, :through => :ride), I think there must be a better way... could you help me please?

Last edited by thorstenhirsch (2013-01-03 18:51:46)