This project is archived and is in readonly mode.
has_one through with new value nil
-
Daniel Guettler
Yes this is still a problem, I just tried it with the current edge version of rails and got:
RuntimeError: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id from /Users/dguettler/workspace/my_projects/rails_testings/has_one_nil/vendor/rails/activerecord/lib/active_record/associations/has_many_through_association.rb:100:in `construct_join_attributes' from /Users/dguettler/workspace/my_projects/rails_testings/has_one_nil/vendor/rails/activerecord/lib/active_record/associations/has_one_through_association.rb:15:in `create_through_record' from /Users/dguettler/workspace/my_projects/rails_testings/has_one_nil/vendor/rails/activerecord/lib/active_record/associations.rb:1265:in `club=' from (irb):7 -
Ben Woodcroft
I can confirm this.
-
John
I can confirm this too.
-
Daniel Guettler
It's still and issue in Rails 2.2.2 right now if you set @member.club = nil it actually doesn't complain about nil anymore but just takes the id of nil and updates the membership. So you end up with a club_id of 4. The old patch doesn't apply anymore to 2.2.2 I'll add a new one. Does anybody know how to "re-open" this ticket?
-
Tarmo Tänav
- State changed from stale to open
-
Daniel Guettler
Thanks for re-opening. I just went through the code and am not quite sure what should actually happen with the Membership when @member.club is set to nil. I basically see 2 options: 1. delete the entry 2. set the club_id to 0 Any opinions?
-
Daniel Guettler
ok, here an updated patch which applies to the 2.2 branch. It will not try to create a new entry if nil is passed and removes existing entries through entries if nil is passed
-
Repository
- State changed from open to resolved
(from [4cd40726eb10fbab269be53c27b304c728541dff]) has_one :through should not create a new association when assigned nil [#698 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/4cd40726eb10fbab269be53c27b304... -
Repository
(from [25724eede9b5a62c74b3b78245944638f1cfcef4]) has_one :through should not create a new association when assigned nil [#698 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/25724eede9b5a62c74b3b782459446...
