Forum: Ruby on Rails Is this a HAS_ONE bug?

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.
Ff43001ac5fe9805aa6ca2e89d3b7b5d?d=identicon&s=25 Jake Janovetz (janovetz)
on 2006-04-15 04:19
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
Ff43001ac5fe9805aa6ca2e89d3b7b5d?d=identicon&s=25 Jake Janovetz (janovetz)
on 2006-04-15 04:29
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.
>
>    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.
This topic is locked and can not be replied to.