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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:44:26+00:00 2026-05-17T01:44:26+00:00

I need to access a legacy relational database via ActiveRecord and that database uses

  • 0

I need to access a legacy relational database via ActiveRecord and that database uses a column named “object_id” as a primary key in a table. Most things work but when I try specify a custom SQL query for an association (see below) ActiveRecord respectively the Ruby interpreter always retrieves the object_id of the Ruby base “Object” instead of the column value from the database.

I defined the following SQL query in a has_many declaration:

:finder_sql => “SELECT * FROM t_object WHERE object_id IN (SELECT end_object_id FROM t_object, t_connector WHERE t_object.object_id = #{object_id} AND start_object_id = #{object_id})

I already tried to solve it by working with an alias:

alias_attribute :my_oid, :object_id

and using “my_oid” in the SQL query. But I got the following error message:

NameError: undefined local variable or method `my_oid’ for EaTObject(Table doesn’t exist):Class

I also defined a method which returns the value of read_attribute(“object_id”) and put the method name into the SQL query instead of “object_id” but when the class was loaded I got the error message that that method name is not a column name in the database table.

Is there any solution to access a column called “object_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-05-17T01:44:27+00:00Added an answer on May 17, 2026 at 1:44 am

    Another option is self[:object_id], but if you are getting “Table doesn’t exist”, then maybe there is something else wrong?

    Edit:
    Try this:

    :finder_sql => 'SELECT * FROM t_object WHERE object_id IN (SELECT end_object_id FROM t_object, t_connector WHERE t_object.object_id = #{id} AND start_object_id = #{id})'
    

    NB! single quotes.

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

Sidebar

Related Questions

I need access to the uint64_t typedef from stdint.h in some wrapper code that
I have two different modules that need access to a single file (One will
I know that's bad design, but I need access to the view from my
I am using playframework with a legacy SQL Server 2008 database that has data
Here's the problem: In C# I'm getting information from a legacy ACCESS database. .NET
We've inherited some legacy software that we need to run quite urgently. It was
We have a legacy class that uses an indexer to allow people to add
I am working on a legacy app that uses Spring Security 2.0.4. I have
I've got an app running maximized in a borderless window and need access to
I am working on a theme for Opencart and am finding I need access

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.