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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:33:10+00:00 2026-06-06T14:33:10+00:00

I want pull the data from only a specific column, but what Is returned

  • 0

I want pull the data from only a specific column, but what Is returned is the whole record.

I went into my console to try and see what was happening under the hood but the results confuse me.

how can I return just the status for each record?

1.9.3p194 :001 > company = Company.first
Company Load (0.1ms)  SELECT "companies".* FROM "companies" LIMIT 1
=> #<Company id: 1, name: "Supreme WIndows", created_at: "2012-06-24 04:12:02", updated_at: "2012-06-24 04:12:02"> 
1.9.3p194 :002 > company.requests
Request Load (0.1ms)  SELECT "requests".* FROM "requests" WHERE "requests"."requestable_id"    = 1 AND "requests"."requestable_type" = 'Company'
=> [#<Request id: 1, status: nil, requestable_id: 1, requestable_type: "Company", created_at: "2012-06-30 01:25:11", updated_at: "2012-06-30 01:25:11", profile_id: nil>, #
     <Request id: 2, status: nil, requestable_id: 1, requestable_type: "Company", created_at: "2012-06-30 01:28:16", updated_at: "2012-06-30 01:28:16", profile_id: nil>, #
     <Request id: 3, status: nil, requestable_id: 1, requestable_type: "Company", created_at: "2012-06-30 01:32:55", updated_at: "2012-06-30 01:32:55", profile_id: nil>, #
     <Request id: 4, status: nil, requestable_id: 1, requestable_type: "Company", created_at: "2012-06-30 02:46:07", updated_at: "2012-06-30 02:46:07", profile_id: nil>] 
1.9.3p194 :003 > company.requests.status
NoMethodError:   Request Load (0.2ms)  SELECT "requests".* FROM "requests" WHERE "requests"."requestable_id" = 1 AND "requests"."requestable_type" = 'Company'
undefined method `status' for #<ActiveRecord::Relation:0x007fdbd57e1ba8>
from /Users/Aaron/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/relation/delegation.rb:45:in `method_missing'
from /Users/Aaron/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/associations/collection_proxy.rb:100:in `method_missing'
from (irb):3
from /Users/Aaron/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /Users/Aaron/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /Users/Aaron/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.3p194 :004 > company.requests.first.status
=> nil 
1.9.3p194 :005 > company.requests.each do |request|
1.9.3p194 :006 >     request.status
1.9.3p194 :007?>   end
=> [#<Request id: 1, status: nil, requestable_id: 1, requestable_type: "Company", created_at: "2012-06-30 01:25:11", updated_at: "2012-06-30 01:25:11", profile_id: nil>, # 
     <Request id: 2, status: nil, requestable_id: 1, requestable_type: "Company", created_at: "2012-06-30 01:28:16", updated_at: "2012-06-30 01:28:16", profile_id: nil>, #
     <Request id: 3, status: nil, requestable_id: 1, requestable_type: "Company", created_at: "2012-06-30 01:32:55", updated_at: "2012-06-30 01:32:55", profile_id: nil>, #
     <Request id: 4, status: nil, requestable_id: 1, requestable_type: "Company", created_at: "2012-06-30 02:46:07", updated_at: "2012-06-30 02:46:07", profile_id: nil>] 
1.9.3p194 :008 > 

All to code for the MCV is in the following question
Rails: How to create polymorphic relationship/friendship model

I have based it on ryan bates polymorphic associtions code
https://github.com/railscasts/154-polymorphic-association-revised/tree/master/blog-after

  • 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-06T14:33:13+00:00Added an answer on June 6, 2026 at 2:33 pm

    Rails 3.1 or later introduced the pluck method for exactly this company.requests.pluck(:status). This queries the DB for just the statuses and returns an array.

    In older versions you can user company.requests.select(:status).map(&:status), here you are instantiating a model for each request and then just pulling out the status, which is a lot more costly.

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

Sidebar

Related Questions

I want to pull data from a database to display into a ComboBox, and
I have a multidocument application. I want to pull data from each of those
I have a remote monotone repos I want to pull from, but I really
Let's say I want to connect to https://www.code.com/secure/test.xml and pull all the data. Before
I've forked a Mercurial repository, and now I want to pull the changes from
I am using jQuery and JSON to pull data from a database. Each row
I want to transmit data from a Queue using Twisted. I currently use a
I am trying to pull data from SQL, and then write it to a
I want to pull out menu items from MySQL. Main menu id=1, parentid=0 -Contact
I'm looking to pull the latest posts from a series of specific users. In

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.