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

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.
41165a7e7126d616a0ae0762e00718e2?d=identicon&s=25 bigsmoke (Guest)
on 2005-11-15 17: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'
end

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.