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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:56:59+00:00 2026-05-26T09:56:59+00:00

When creating named scopes in a model, is it necessary to call the model

  • 0

When creating named scopes in a model, is it necessary to call the model before the attribute that you are using in your query?

Example

  scope :sorted, order('position ASC')

vs

  scope :sorted, order('pages.position ASC')

is the latter preferred, or inline with conventions? are there benefits to either? or is it just a matter of clarity or legibility?

  • 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-26T09:56:59+00:00Added an answer on May 26, 2026 at 9:56 am

    You will need to declare the model if the scope will be used with a join with another model, which has a field with the same name.

    Say the company has_one :contact, and the Contact has a position. Then

    Company.sorted.joins(:contact)
    

    will complain (on the SQL level) that it’s unclear which of the position fields should be used for sorting.

    Otherwise it’s optional.

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

Sidebar

Related Questions

I'm creating a class named TetraQueue that inherits System.Collections.Generic.Queue class overriding the Dequeue method,
I've added a scope to a Rails model that allows for searching based on
I'm creating a temp image always named 1.png under specific folder and once i
I am creating a MKMapView in a method named generateMap. From inside viewDidLoad, this
I implemented Forms authentication by creating Default.aspx and custom login page named login.aspx .
In SharePoint, a file named ONET.xml is usually needed when creating a custom site
In VS2008, you could enable right-margin marks by creating a string registry entry named
I have a Model which I am using to track permissions in a hierarchical
Creating a calculator-like dialog, I noticed that quickly clicking on a button in IE
I have a couple of models which share a has_many associations, named scopes and

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.