Let''s say I have: A BELONGS_TO B B HAS_ONE A (with :dependent=>:nullify) But this association does not need to exist. In other words, I could have many A''s and B''s that are not associated in this manner. Presently, if I try to delete "B": 1. If B is associated to an "A", this works fine and A.my_B is nullified. 2. If B is NOT associated, I get an error saying it is trying to call "nil.update_attribute" (presumably trying to set the my_B to nil.) Seems to me this is a bug -- if my_B is already nil, nothing should happen; Rails should just happily delete B. Jake -- Posted via http://www.ruby-forum.com/.
Jake Janovetz wrote:> Let''s say I have: > > A BELONGS_TO B > B HAS_ONE A (with :dependent=>:nullify) > > But this association does not need to exist. In other words, I could > have many A''s and B''s that are not associated in this manner. > > Presently, if I try to delete "B": > 1. If B is associated to an "A", this works fine and A.my_B is > nullified. > 2. If B is NOT associated, I get an error saying it is trying to call > "nil.update_attribute" (presumably trying to set the my_B to nil.) > > Seems to me this is a bug -- if my_B is already nil, nothing should > happen; Rails should just happily delete B. > > JakeActually, I just noticed that HAS_ONE doesn''t actually have a ''nullify'' option for ''dependent'' and that not specifying any option seems to do what I want. Interesting. -- Posted via http://www.ruby-forum.com/.
Apparently Analagous Threads
- #5209 patch: :dependent => :nullify deletes child records
- has_one :dependent => :destroy error (in `configure_dependency_for_has_one': compile error (SyntaxError))
- Destructive behavior with link_to, button_to, :post=>true
- Encrypting source / application licensing
- Simply Ruby question: "zerofill"