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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:38:05+00:00 2026-05-25T16:38:05+00:00

Update I am trying to do is select specific columns and use aliases on

  • 0

Update

I am trying to do is select specific columns and use aliases on them, and use it in a named_scope. I want to use aliases because later on I’ll use this as an idea when I try to join many tables, based on the SQL that I have created.

Edit:
Im running in Rails 2.3.8 and Ruby 1.8.7


Here is my named_scope…

named_scope :prog_result,:select => "users.id AS 'user_id', users.username AS 'username', users.lastname AS 'lastname', users.firstname AS 'firstname', departments.name AS 'department', versions.number AS 'version'", 
                         :joins => {:department => :version}

And when I try to call it in console User.prog_result the result is this…

[#<User username: "respondent1", lastname: "res", firstname: "pon">, #<User username: "2222", lastname: "Numero", firstname: "Dos">]

User.prog_result.find(2) 2 is the id of the user “respondent1”, the result of User.prog_result.inspect is this

"[#<User username: \"respondent1\", lastname: \"res\", firstname: \"pon\">, #<User username: \"2222\", lastname: \"Numero\", firstname: \"Dos\">]"

Can someone tell me what am I doing wrong?..

  • 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-25T16:38:06+00:00Added an answer on May 25, 2026 at 4:38 pm

    When you call User.prog_result in the console, you are really calling User.prog_result.inspect The console is displays the result by calling #inspect on the result object.

    If instead you called User.prog_result.class in the console, you’d see that it was an ActiveRecord::NamedScope::Scope.

    If you poke inside these objects that are being returned, you’ll probably find what you are expecting.

    User.prog_result.first.department => first joined department.name
    User.prog_result.last.version   => last joined version.number
    

    Both named scopes and passing :joins, :conditions and :select are deprecated in Rails 3.1, so you should probably not be developing new code with them unless you are on Rails 2.3.x. You’ll want to do something like this:

    User.joins(:department => :version).
    select("users.id AS 'user_id', users.username AS 'username', users.lastname AS 'lastname', users.firstname AS 'firstname', departments.name AS 'department', versions.number AS 'version'")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use filters to select specific tables to replicate. I tried
I'm trying to update some properties with KVC. The properties have been synthesized. This
I'm trying to use checkboxes to add users to a specific group but I'm
I am trying to update a specific row that uses auto_increment as a primary
I am trying to update the Roles a specific group has in my application.
I'm trying an update with a conditional sub-select which could return null... UPDATE aTable
I'm trying to update multiple columns in a MS SQL statement using a sub-query.
I'm currently trying to update a specific <div> element on my page with the
I am currently trying to issue an update to specific rows of a mysql
I am trying update my version of sqlite3 on mac os x 10.5.7 I

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.