Thanks! Although your answer didn't solve the issue at hand, it
definitely put me on the right track!
The solution I found was to use the :include key in the maximum
method. This is what I ended up with:
def total_time
@flight = Flight.find(self.id)
@flight_hours = FlightTime.maximum( :hours,
:include => [:flight_type],
:conditions =>
['flight_types.count_to_total != "f"'],
:group => :flight
)
@[EMAIL PROTECTED]
end
On Oct 10, 11:24 pm, Frederick Cheung <[EMAIL PROTECTED]>
wrote:
> maximum take most of the options that find does, eg :conditions
> and :joins
>
> Fred
>
> Sent from my iPhone
>
> On 10 Oct 2008, at 21:01, Alex <[EMAIL PROTECTED]> wrote:
>
>
>
> > 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) <---
> > flight_types (table)
>
> > The flight_times are connected to flights with column flight_id, and
> > to the flight_types via flight_type_id.
>
> > flight_times (table)
> > :flight_id
> > :flight_type_id
> > :hours (decimal)
>
> > In order to fetch the flight_times with the highest hours count
> > belonging to a specific flight, I use the following function:
>
> > def total_time
> > [EMAIL PROTECTED] = Flight.find(self.id)
> > [EMAIL PROTECTED] = FlightTime.maximum(:hours, :group => :flight) #
> > FlightTime :belongs_to :flight
> > [EMAIL PROTECTED]@flight].to_s
> > end
>
> > 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:
>
> > flight_types (table)
> > :name
> > :count_to_total (boolean)
>
> > 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?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---