I need to use legacy relational database through an ActiveRecord and in that database the primary of the column called "object_id" The key is used as the table. Most things work but when I try to specify a custom SQL query for an Association (see below) ActiveRecord, Ruby Interpreter always receives the object_id of Ruby Base "Object" instead of the column value from the database. .
I defined the following SQL query in 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 = # {objective_id})
I already tried to solve it by working with a nickname:
alias_attribute: my_oid,: object_id
and using "my_oid" in the SQL query. But I have received the following error message:
NameError: Undefined local variable or EaTObject (rhythm The method for 'my_oid' does not exist): Class
I have also defined a method that returns the value of read_attribute ("object_id") and put method name in th Returns the e-SQL query instead of "object_id", but when the class was loaded, I get an error message that the name of that method is not the name of a column in the database table.
Object_ID "
Another option self [: object_id]
, but if you are getting "the table does not exist", then maybe something is wrong?
EDIT: Try it out:
: finder_sql = & gt; 'SELECT * FROM t_object in WHERE object_id (SELECT end_object_id FROM t_object, t_connector WHERE t_object.object_id = # {id} and start_object_id = # {id})'
NB! Single quotes
Comments
Post a Comment