-1

I am having a hard time connection to my SQL Server 2005 data on a Windows 7 machine.

I created a table and model following ruby's standards and can connect with the console and get the field names. I can not get it to work with any existing tables.

I created this model which does not work:

class Employee < ActiveRecord::Base

    set_table_name = 'EMP'
    primary_key = 'EMP_EmployeeID'

end

However if I add a table called employees with a primary key of 'id' the model works, albeit taking the fields from the table I added and ignoring the real table.

Any one have any clue on how I can get this to work?

Joe
  • 379
  • 1
  • 6
  • 21

1 Answers1

1

Modify your code::::

self.table_name = "EMP"
self.primary_key = "EMP_EmployeeID"

set_table_name and primary_key, does not imply anything

Sheharose
  • 295
  • 3
  • 14
  • Made the change and I still get this: Employee(Table doesn't exist). I even tried self.table_name = 'dbo.EMP' but that did not work either. – Joe Jul 17 '15 at 19:12
  • your table name is EMP not Employee – Sheharose Jul 17 '15 at 19:57
  • Yes, thats what I tried to explain to you. The table name is EMP. The model is Employee. When you use the rails console you use the class name NOT the table name. When I tried to instantiate the class Employee which maps to table EMP I received the error "Table doesn't exist". Fortunately Steve Klein pointed out the solution here http://stackoverflow.com/questions/31463738/using-ruby-on-rails-with-sql-server-mixed-case-database – Joe Jul 23 '15 at 13:23