Association broken when upgrading from rails 1.2.6 to 2.2.2

I have an app with the following models: course belongs_to :semester

semester has_many: courses belongs_to :education

education has_many :semesters

In my old app (rails 1.2.6) I was able to access variables via

controller @courses = Course.find(:all)

view file: <% for course in @courses %> <%= course.name %> <- this line works <%= course.semester.name %> <- this is now broke <%= course.semester.education.name %> <-this is now broken.

When upgrading to rails 2.2.2 all this is broken. What changed?

I only changed the enviroment.rb to rails 2.2.2 and did rake rails:upgrade

In my old app (rails 1.2.6) I was able to access variables via

controller @courses = Course.find(:all)

view file: <% for course in @courses %> <%= course.name %> <- this line works <%= course.semester.name %> <- this is now broke <%= course.semester.education.name %> <-this is now broken.

When upgrading to rails 2.2.2 all this is broken.

In what way is it broken ? What happens ?

Fred

Error: You have a nil object when you didn't expect it! The error occurred while evaluating nil.name

the view   <%= link_to course.semester.name, :controller => 'reporting', :action => 'new', :id => course.id %>

the database: courses

in that view, does   <%= course.class %>   <%= course.semester_id %> give you something like this   Course   32

jep, you are 100% correct.

And is there a semester with that id ?

Fred

This is so embarrising. No, when doing rake up and down, all of my fixtures files are interpeted differently. so now I have to specify the id column, it's not just a normal incriment column, when migrating :frowning:

Sorry for all the fuss, I just completely missed this.

This is so embarrising. No, when doing rake up and down, all of my fixtures files are interpeted differently. so now I have to specify the id column, it's not just a normal incriment column, when migrating :frowning:

That is a rails 2.something differnce: if the id column is not specified it is autogenerated according to some deterministic method. THis is part of something called "foxy fixtures". What it boils down to is that you used to have to have stuff like

bobs_order:   user_id: 4

in orders.yml

and bob:    id: 4    name: bob in users.yml.

since this change you can have

bobs_order:   user: bob

and bob:   name: bob

Because rails knows what id bob will be assigned it can wire things up and you end up with neater fixture files without a million hardcoded ids.

Fred

jep, I fixed the problem, by manually editing my .yml file...

I am so sorry for not realising the stupid simple issue. It would be nice if there was a way to avoid editing every line on your yaml file :frowning: Some kind of switch. But I can't find one.

Thanx for all of your patient help.

And have a wonderfull weekend.

regards svend