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

  • Home
  • SEARCH
  • 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 6993773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:48:25+00:00 2026-05-27T19:48:25+00:00

What is the Rails 3.1 of writing the code below: named_scope :min_2_items_last_90_days, { :include

  • 0

What is the Rails 3.1 of writing the code below:

named_scope :min_2_items_last_90_days, {
    :include => { :orders => :order_items },
    :conditions => ['orders.created_at >= ?', 90.days.ago],
    :group   => 'people.id',
    :having => 'COUNT(order_items.id) >= 2'
  }
  • 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-27T19:48:26+00:00Added an answer on May 27, 2026 at 7:48 pm

    While writing it as

    scope :min_2_items_last_90_days, where(...)
    

    is syntactically correct, it probably (like your original code) doesn’t do quite what you think.

    In both cases the 90.days.ago is evaluated once only, when the class is loaded, so the 90 days will always be 90 days before you app was last restarted. If you haven’t restart your app for 10 days you’d actually be looking at stuff created in the last 100 days. You won’t notice this in development because your source code is continuously being reloaded (and thus the 90.days is reevaluated).

    Instead you should do

    scope :min_2_items_last_90_days, lambda { where('orders.created_at >= ?', 90.days.ago).includes(...) ... }
    

    which ensures that the conditions will be re-evaluated every time you use the scope.

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

Sidebar

Related Questions

I am writing some Ruby code, not Rails, and I need to handle something
I'm writing some Rails code for a partial view, and I want it to
Current verbose rails path helpers I'm constantly writing code to get URLs like: link_to
I'm writing a Ruby on Rails app. The following jQuery code is included in
We are writing a Rails application that is using CouchDB as its data store.
I'm currently writing a Rails app, and hit a somewhat strange quirk. I have
I started writing functional tests for my rails app today. I use the RESTful
I'm writing a non-Rails ruby application (gasp!) and would like to be able to
I'm writing an Ruby on Rails app using a legacy database. The problem I'm
I am writing my first rails app. It needs to aggregate some data from

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.