Bug #4567
open
Unable to reliably unset all object associations
Added by Dominic Cleal about 11 years ago.
Updated about 11 years ago.
Description
I'm trying to remove all associated domains from a subnet, but failing to find a reliable means. None of the examples below actually remove the associated domains, unless I add another domain in the array to replace it.
PUT /api/v2/subnets/1
{"domains":[]}
PUT /api/v2/subnets/1
{"domain_ids":[]}
PUT /api/v2/subnets/1
{"domain_ids":null}
Related issues
1 (1 open — 0 closed)
Examples 2 and 3 work fine, but only if you wrap the entire object (which isn't meant to be necessary in the API):
{"subnet":{"domain_ids":[]}}
{"subnet":{"domain_ids":null}}
Example 1 if you wrap it then throws an exception (this may be a separate bug):
{"subnet":{"domains":null}}
undefined method `each' for nil:NilClass (NoMethodError)
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/associations/collection_association.rb:310:in `replace'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/associations/collection_association.rb:41:in `writer'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/associations/builder/association.rb:51:in `block in define_writers'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/attribute_assignment.rb:78:in `each'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/persistence.rb:216:in `block in update_attributes'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/transactions.rb:208:in `transaction'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
/home/dcleal/.rvm/gems/ruby-2.0.0-p247@foreman/gems/activerecord-3.2.17/lib/active_record/persistence.rb:215:in `update_attributes'
/home/dcleal/code/foreman/foreman/app/controllers/api/v2/subnets_controller.rb:60:in `update'
- Related to Bug #4571: "Domain (..) expected, got ActiveSupport::HashWithIndifferentAccess(..)" when setting associations with wrapped object added
Also available in: Atom
PDF