ruby on rails - How to retrieve values from a column called "object_id" in ActiveRecord? -



ruby on rails - How to retrieve values from a column called "object_id" in ActiveRecord? -

i need access legacy relational database via activerecord , database uses column named "object_id" primary key in table. things work when seek specify custom sql query association (see below) activerecord respectively ruby interpreter retrieves object_id of ruby base of operations "object" instead of column value database.

i defined next sql query in has_many declaration:

:finder_sql => "select * t_object object_id in (select end_object_id t_object, t_connector t_object.object_id = #{object_id} , start_object_id = #{object_id})

i tried solve working alias:

alias_attribute :my_oid, :object_id

and using "my_oid" in sql query. got next error message:

nameerror: undefined local variable or method `my_oid' eatobject(table doesn't exist):class

i defined method returns value of read_attribute("object_id") , set method name sql query instead of "object_id" when class loaded got error message that method name not column name in database table.

is there solution access column called "object_id"?

another alternative self[:object_id], if getting "table doesn't exist", maybe there else wrong?

edit: seek this:

:finder_sql => 'select * t_object object_id in (select end_object_id t_object, t_connector t_object.object_id = #{id} , start_object_id = #{id})'

nb! single quotes.

ruby-on-rails ruby activerecord

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -