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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:07:39+00:00 2026-05-25T21:07:39+00:00

I have this named_scope in one of my models: named_scope :latest_100, :from => ‘(select

  • 0

I have this named_scope in one of my models:

named_scope :latest_100,
            :from => '(select * from videos order by videos.created_at desc limit 0, 100) as videos'

Its purpose is to create a pool of the last 100 videos (returning that results as ‘videos’ so the other scopes operate on that dataset), and then I can chain scopes after that and filter records out of that pool of results.

# video.rb
named_scope :most_popular, :order => 'popularity'
named_scope :take_5, :limit => 5

# video_controller.rb
# it gets the latest 100 videos, then sorts those by popularity, and takes the top 5.
@videos = Video.latest_100.most_popular.take_5

Is there an equivalent statement for 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-25T21:07:40+00:00Added an answer on May 25, 2026 at 9:07 pm

    There exists a .from() method in Arel.

    I used it in the following manner:

    # video.rb
    scope :latest_100, from('(select * from videos limit 100 order by created_at desc) as videos')
    scope :most_popular, order('popularity')
    scope :take_5, limit(5)
    
    # video_controller.rb
    @videos = Video.latest_100.most_popular.take_5
    

    The latest_100 will create a pool of valid videos from which you can pull the top 5 most popular.

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

Sidebar

Related Questions

please help me to parse xml from another xml... i have this xml named
I have one ViewController, in this i have added one Custom UIView named as
I have a table named datas and I'm executing a query like this: SELECT
I have a Django application that defines a one-to-many model relationship. The models look
I have form like this: <div class=satu> <input type='text' size='1' maxlength='1' name='score[1][]' id='score[1][]'> </div>
I have this following setup, a textarea named with some data in it that
We have a couple of thousand files in a directory named like this: EXP_10000021.XM_
how do i have to nest multicheckboxes so that they are named like this
I have a named list that looks like this: > head(pathways) $<NA> NULL $`2`
I have a class named Person and in this class is the property PersonName

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.