I am developing a RoR project using an Oracle database. Recently I added a DBLink to another database and this works perfectly just from an SQL.
When I want to add the table to my class with the following code…
class ServerModel < ActiveRecord::Base
set_table_name "S985.S985_947_MODELS_VW@R985_A947.WORLD"
set_primary_key "model_barcode"
acts_as_reportable
acts_as_entity
end
… I get this error:
NativeException: java.sql.SQLException: ORA-02084: database name is missing a component
: select * from (SELECT "S985"."S985_947_MODELS_VW"@"R985_A947"."WORLD".* FROM "S985"."S985_947_MODELS_VW"@"R985_A947"."WORLD" ) where rownum <= 14
Of course this automatically used query does not work. It shouldn’t select "S985"."S985_947_MODELS_VW"@"R985_A947"."WORLD".* but just "S985"."S985_947_MODELS_VW".*, without duplicating the name of the dblink (@R985_947.WORLD).
Is this possible with the set_table_name method or any other ActiveRecord method?
The answer looks simple, but I cannot find the solution. Can anybody help me with this problem?
Thanks!
Unsure about tweaking Active Record to include the DB Link name, but what about creating a view of the remote table, something like:
And then just accessing the view in the ROR application? Not sure if the view can be inserted, updated etc – you would need to check that out. I have a feeling a ‘simple’ view (ie one on a single table without group by etc) can be updated and inserted into.