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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:28:05+00:00 2026-06-11T09:28:05+00:00

I want to know field name corresponding to table caption for a given model

  • 0

I want to know field name corresponding to table caption for a given model in Rails.

I am displaying captions using a query model.

query.columns.map{|q| q.caption}
=> [“Tracker”, “Status”, “Priority”, “Subject”, “Assignee”, “Target version”, “Due date”, “% Done”]

Column has names corresponding to captions

query.columns.map{|q| q.name}
=> [:tracker, :status, :priority, :subject, :assigned_to, :fixed_version, :due_date, :done_ratio]

My model looks like

Issue.columns.map{|q| q.name}
=> [“id”, “tracker_id”, “project_id”, “subject”, “description”, “due_date”, “category_id”, “status_id”, “assigned_to_id”, “priority_id”, “fixed_version_id”, “author_id”, “created_on”, “updated_on”, “start_date”, “done_ratio”, “estimated_hours”, “parent_id”]

I want to get field name(the db field name) corresponding to a caption from the above information.

Sample association in the model

belongs_to :assigned_to, :class_name => 'Principal', :foreign_key => 'assigned_to_id'

So for above association i want to know the foreign key.

for assigned_to i want 'assigned_to_id'

  • 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-11T09:28:06+00:00Added an answer on June 11, 2026 at 9:28 am

    The reflections hash holds this kind of information:

    Issue.reflections['assigned_to'].foreign_key
    

    You can also get other information, such as the class (.active_record) or the type of association (.macro). Prior to rails 4.2, the keys of this hash are symbols and not strings.

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

Sidebar

Related Questions

I just want to know which is max length of field name of a
how to know the field variable name when output by views. eg:now, i want
want to know why String behaves like value type while using ==. String s1
I have a mysql table containing a field name dtt_date and have values like
I want to know how I can get the datatype of each field in
I want to ask if anybody know the query to drop the 0 value
Is there a way to get the field name with the given getter method.
i want know how i can manage multiple twitter account on iOS in my
i want know if is possible, to get a specific element value of a
please help me. I want know about what types of flags to run an

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.