Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3847606
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:34:39+00:00 2026-05-19T16:34:39+00:00

This returns the maxium value , not the complete record: self.prices.maximum(:price_field) And currently, I

  • 0

This returns the maxium value, not the complete record:

self.prices.maximum(:price_field)

And currently, I find the record like this:

def maximum_price
  self.prices.find(:first, :conditions => "price = #{self.prices.maximum(:price_field)}" )
end

Is this the correct way ? Because the above needs two SQL statements to make it work, and it somehow does not feel right.

Ps. Additionally, I want that if more than one record has the same "maximum" value, then it should get the one with the latest updated_at value. So that would mean another SQL statement??

Pps. Does anyone know of a good or detailed reference for AREL and non-AREL things in Rails? The Rails Guide for ActiveRecord query is just not enough!

(I’m using Rails 3)

===UPDATE===

Using AREL I do the following:

self.prices.order("updated_at DESC").maximum(:price_field)

But this only gives the maximum value, not the complete record 🙁
Also, is the use of maximum() really AREL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:34:40+00:00Added an answer on May 19, 2026 at 4:34 pm

    How about something like this?

    self.prices.order("price DESC").first
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a function like def f(): ... ... return [list1, list2] this returns
Is there a standard function that returns the position (not value) of the maximum
In Oracle, this returns 03/01/2010. That does not make sense to me. Anybody know
I use SmartGwt and I have the following line: formItem.getForm().getField(report_date).getValue().toString(); This returns something like
Here's an example: Double d = (1/3); System.out.println(d); This returns 0, not 0.33333... as
Given this array int [] myArray = {5,-11,2,3,14,5,-14,2}; You are to find the maximum
Can someone explain to me why this returns an empty string () instead of
CAST(IH.InvoiceDate AS date) AS InvoiceDate this returns 2012-03-16 is it possible to format this
private void EnsureCurrentlyValid() { //I'm valid if IDataErrorInfo.this[] returns null for every property var
I'm trying to decode the result of the Python os.wait() function. This returns, according

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.