Deleting a reference that uses a belongs_to association


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