# MS SQL (legacy) relations not working

**URL:** <https://www.ruby-forum.com/t/ms-sql-legacy-relations-not-working/105602>\
**Category:** Rails\
**Created:** [May 31, 2007, 4:47pm UTC](https://www.ruby-forum.com/t/ms-sql-legacy-relations-not-working/105602 "2007-05-31T16:47:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 31, 2007, 4:47pm UTC](https://www.ruby-forum.com/t/ms-sql-legacy-relations-not-working/105602/1 "2007-05-31T16:47:26Z")

</div>

I have my app talking to the MS SQL database. meaning I can retrieve  
data from it.  
I have an Office table. and it has a column called ‘Marketing’ that is  
a foreign key to the marketing tables primary key.

so I was have trouble and I set up a test environment on mac using  
Locomotive.  
I set the tables up the same way as the MQ SQL server.

## here are the models

class Office \< ActiveRecord::Base  
set\_table\_name “Office”  
self.primary\_key = “OfficeID”

## belongs\_to :marketing, :class\_name =\> “Marketing”, :foreign\_key =\> “Marketing” end

class Marketing \< ActiveRecord::Base  
set\_table\_name “marketing”  
self.primary\_key = “marketingid”

## has\_many :offices end

/\*\*\* controller \*\*\*/  
class OfficeController \< ApplicationController

## def index @offices = Office.find(:all) end end

/\*\*\* index.rhtm \*\*\*/

## \<% for office in @offices %\> \<%= office.Name %\> - \<%= office.marketing.first\_Name %\> \<% end %\> \<%= debug @offices %\>

this code works with the locomotive set up (MySQL database) and the  
instant rails set up with MySQL database  
but when I use the same code on the instantrails using the MS SQL  
server I get this error.

* * *

## You have a nil object when you didn’t expect it! The error occurred while evaluating nil.first\_name

I am confused.  
if I take out the \<%= office.marketing.first\_Name %\> part of code it  
runs and in the debug it shows “Marketing”=\>4 - which is correct but  
it also doesn’t show the marketing object within the office object.

anybody have any ideas?
