Forum: Ruby on Rails Deleting a reference that uses a belongs_to association

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
bigsmoke (Guest)
on 2005-11-15 18:09
(Received via mailing list)
Is it possible to delete a record or to nullify the foreign key for a
record that is associated using a belongs_to association?

For example:

class BelieverOrNot < ActiveRecord::Base
  belongs_to :deity, :foreign_key => 'deity_id'

believer = new BelieverOrNot( :deity =>
Deity.find_by_num_worshippers('5') )

# Our believer stops believing, but the reference can't be destroyed

believer.deity = nil # Doesn't work
believer.deity_id = nil # Neither does this

After saving "believer", the foreign key will still hold the same old
value. What's wrong with this? What are we doing wrong?

 - Rowan
This topic is locked and can not be replied to.