Hans <Hans.Marmolin@...> writes:

> 
> I'm trying to set up a self-referential relationship, as described in
> this great video - http://railscasts.com/episodes/163-self-referential-
association
> - and it's mostly working, but not entirely.
> 
> My self-referential relationship describes relationships between
> people using the foreign keys person and related_person in class
> Relationship both associating to the class Person
> 
> My problem is that when I update related_person_id for a specific
> relationship  the associated object relationship.related_person is not
> updated. Related_person_id in relationship has an updated value,
> while  relationship.related_person.id has the old value.
> What is wrong in my declarations ??
> They are as follows
> 
> Class Person
> 
> has_many                :relationships, :dependent=>:destroy, :autosave=>true
>   has_many                :people, :through
> => :relationships, :source=>:person,  :uniq=>true
>   has_many                :related_people, :through
> => :relationships, :source=>:related_person,  :uniq=>true
> 
> Class Relationship
>   belongs_to  :person
>   belongs_to  :related_person, :class_name => 'Person',:foreign_key
> =>'related_person_id'

The code looks OK to me.  Are you sure it's not a caching/stale record 
problem?  Fire up a console and execute your code manually.  If you see the 
same error try reloading the instance, eg:

person.reload

This will ensure you are looking at a current version from the database rather 
than a (possibly) stale version in Ruby memory.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to