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”:
- If B is associated to an “A”, this works fine and A.my_B is
nullified.
- 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
Jake J. 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”:
- If B is associated to an “A”, this works fine and A.my_B is
nullified.
- 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
Actually, 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.