Actions
Bug #4567
openUnable to reliably unset all object associations
Status:
New
Priority:
Normal
Assignee:
-
Category:
API
Target version:
-
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}
Updated by Dominic Cleal over 10 years ago
https://github.com/Apipie/apipie-rails/pull/188 might be relevant or useful here, for keeping empty arrays instead of nil.
Updated by Dominic Cleal over 10 years ago
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'
Updated by Dominic Cleal over 10 years ago
- Related to Bug #4571: "Domain (..) expected, got ActiveSupport::HashWithIndifferentAccess(..)" when setting associations with wrapped object added
Actions