Forum: Ruby on Rails Can't replace/remove a has_one related object

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Wes G. (Guest)
on 2007-04-16 22:54
All,

I have two models, Job and Document.

Job has_one :document

I perform this:

@current_job.document.destroy

which successfully removes all the appopriate DB records.

However, if I attempt to do:

  @current_job.document = nil

OR

  @current_job.build_document(...)

I get a TypeError: can't modify frozen hash exception.

Why can't I reassign nil to the associated document for my job?

Thanks,
Wes
Wes G. (Guest)
on 2007-04-16 23:02
OK, I see now that the destroy instance method says that it "freezes
this instance to reflect that no changes should be made (since they
can‘t be persisted)."

Fine.  I don't want to work with that instance any more.

Why can't I reassign to the has_one relationship?

Wes
This topic is locked and can not be replied to.