Hey guys, I have a problem you’ll hopefully be able to help me with.
I’m developing a logbook, and I have the following database structure:
users (table) —> flights (table) —> flight_times (table) <—
The flight_times are connected to flights with column flight_id, and
to the flight_types via flight_type_id.
In order to fetch the flight_times with the highest hours count
belonging to a specific flight, I use the following function:
@flight = Flight.find(self.id)
@flight_hours = FlightTime.maximum(:hours, :group => :flight) #
FlightTime :belongs_to :flight
So far so good, it returns the value of the highest :hours count.
HOWEVER, here starts the difficulty for me.
The flight_types table has two columns:
If the :count_to_total is false, I do not want it to be included when
the total_time method looks for the maximum value.
Did you get that?