Help needed to construct complex query

Hi all,

I am really trying to not use a native sql statement for the
following.

Basically, I am trying to solve the same problem described here:
http://stackoverflow.com/questions/4687515/adding-a-computed-column-to-an-activerecord-query

However, I need to do this in a parent child relationship.

Parent object contains (Latitude, Longitude, name, ....), Child object
contains (expired_time, start_time, ....) and it is a has_many
relationship.

here is my code: