0

I'm a bit new to Sinatra / Datamapper and I am currently attempting to create a model based on an existing table.

We have an employee forum which stores the users' employee ID when they create a post. Obviously when we display the information, we want to show the employees' real name (rather than their employee ID), so we have a quick reference table that is truncated and repopulated daily with the following information:

EMPLOYEE_ID (NUMBER)
FORENAME (VARCHAR2 150)
SURNAME (VARCHAR2 150)

I'm attempting to use the following code:

require 'data_mapper'
DataMapper.setup(:default, 'oracle://xxx:xxx@xxx.xxx')

class Emp
    include DataMapper::Resource
    storage_names[:legacy] = 'emps' # Added as advised by Yevgeniy       

    property :employee_id,  Serial,    :field => 'employee_id' # Added as advised by Bala
    property :forename,     String
    property :surname,      String
end

DataMapper.finalize

When I run

employees = Emp.all
employees.inspect

It only returns [ ]

Any idea what am I doing wrong?

ash
  • 1,224
  • 3
  • 26
  • 46
  • 1
    You should provide table's name after `include` operator, something like `storage_names[:legacy] = '...name of legacy table...'` – Yevgeniy Anfilofyev Sep 12 '13 at 12:35
  • Hi Yevgeniy, thanks for your reply. I have added storage_names[:legacy] = 'emps' but it's still returning []. – ash Sep 12 '13 at 12:52
  • 1
    could you try changing `employee_id, Integer` to `employee_id, Serial` – Bala Sep 12 '13 at 12:58
  • Thanks Bala - Added that but no change (still getting []) - It's worth mentioning that there is no PK on this table (as the data is not edited and is truncated and reinserted every day). – ash Sep 12 '13 at 13:04
  • Got it working - forgot to do a commit which caused a NOWAIT error *doh* - thank you for all your help. – ash Sep 12 '13 at 13:17

0 Answers0