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"?