Perhaps this is intentional, but it seems unlikely:

class Person < ActiveRecord::Base
 belongs_to :school
end

p = Person.find(:first)
p.school # nil
p.school_id = School.find_by_name('High School').id
p.school.name # High School
p.school_id = School.find_by_name('Primary School').id
p.school.name # High School <= Shouldn't this be Primary School?
p.school.id == p.school_id # false !!!

Of course, p.school(:reload) works fine, but I think it would be nice
for the association accessor to check that the foreign keys match up
and reload the association if they don't. This should only be
necessary for belongs_to.

A more disturbing example may be something like:

def save
 @person = Person.find(params[:id], :include => :school)
 @person.update_attributes(params[:person])

 # @person.school will refer to the old school, even if a new
school_id was passed in the params
end

Thoughts?

-Jonathan.
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to