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
I set the tables up the same way as the MQ SQL server.
here are the models
class Office < ActiveRecord::Base
self.primary_key = “OfficeID”
:class_name => “Marketing”,
:foreign_key => “Marketing”
class Marketing < ActiveRecord::Base
self.primary_key = “marketingid”
/*** controller ***/
class OfficeController < ApplicationController
@offices = Office.find(:all)
/*** 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?