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 8981647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:23:18+00:00 2026-06-15T20:23:18+00:00

Just wondering if there is any function that allows to do that: MyModel.find_by_conditon(method_a –

  • 0

Just wondering if there is any function that allows to do that:

MyModel.find_by_conditon(method_a - method_b > 0)

MyModel.class

def method_a
  next_service_date.to_i
end

def method_b
  last_service_date.to_i
end
def next_service_date
  service_date.present? ? calculated_time_estimation : row_time_estimation
end
def calculated_time_estimation
  service_date + calculated_service_period
end
def calculated_service_period
      case(service_frequency_period)
      when 'Year'
        service_frequency_number.to_i.year
      when 'Month'
        service_frequency_number.to_i.month
      when 'Week'
        service_frequency_number.to_i.day * 7
      when 'Day'
        service_frequency_number.to_i.day
      end
end

service_frequency_number, service_frequency_period, service_date are attributes for MyModel

  • 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-06-15T20:23:20+00:00Added an answer on June 15, 2026 at 8:23 pm

    Assuming that method_a and method_b are actually attributes, you can do:

    MyModel.where('method_a - method_b > ?', 0)
    

    Edit

    I think the only way that you’re going to be able to query on a calculated field is to move the calculation to the DB, where you would have a scalar function to return the results. Then you could do MyModel.where('next_service_date_on_db(service_date) > 0'). Unfortunately, that would tie you to a DB-specific implementation, but you’re not going to be able to query that way without a server-side function.

    Now, if you have the entire collection, you could filter based on those conditions, but you’ll have to load the entire set. For example:

    MyModel.all.select {|m| m.method_a - m.method_b > 0}
    

    #all returns an array of all of the objects, and select filters based on the condition of the block. Unfortunately, this solution loads all of the records to sort application side.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I'm just wondering if there's any easy function to make text suitable to
i just wondering is there any performance issue or anything thing wrong if that
Just wondering if there is any benchmark software that I can download that will
I am wondering is there any function that would return the current time in
Im just wondering if anyone knows of any JS libraries out there that allow
Was just wondering if there are any built in functions in c++ OR c#
Just wondering is there any way I can check whether the url links to
Just wondering if there is any way to get the NS records in C#.
Just wondering if there are any pitfalls using .net as the extension for a
Was just wondering if there was any software out there to do this? The

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.