association can't be changed

Hi, all! May you ever feel happy!

I'm getting some very strange behaviour and I'm not sure where my mistake lies.

I have a Divination model that belongs_to :book.

I get the following in script/console:

d = Divination.find(7) # => #<Divination id: 7, user_id: 1, book_id: 4... d.book # => #<Book id: 4...

Now if I change the book:

d.book = Book.find(5) # => #<Book id: 5... d.book # => #<Book id: 4

# It's still the same! Now I try to change the book_id:

d.book_id = 6 # => 6 d.book_id # => 6

Wow! It changed!

d.book # => #<Book id: 4

But alas! The book is the same!

It certainly shouldn't be this way, should it? Or am I missing something very important?

Yours, Damian

P.S. It is Rails 2.0.2 on Mac OS X 10.5 Leopard

Now if I change the book:

d.book = Book.find(5) # => #<Book id: 5... d.book # => #<Book id: 4

should be: d.book << Book.find(5)

Now I try to change the book_id:

d.book_id = 6 # => 6 d.book_id # => 6

Wow! It changed!

d.book # => #<Book id: 4

not sure, but maybe you would have to save the thing, before the id change changes the book?