Project

General

Profile

Actions

Bug #4567

open

Unable to reliably unset all object associations

Added by Dominic Cleal about 10 years ago. Updated about 10 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
API
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

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 open0 closed)

Related to Foreman - Bug #4571: "Domain (..) expected, got ActiveSupport::HashWithIndifferentAccess(..)" when setting associations with wrapped objectNew03/06/2014Actions
Actions #1

Updated by Dominic Cleal about 10 years ago

https://github.com/Apipie/apipie-rails/pull/188 might be relevant or useful here, for keeping empty arrays instead of nil.

Actions #2

Updated by Dominic Cleal about 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'

Actions #3

Updated by Dominic Cleal about 10 years ago

  • Related to Bug #4571: "Domain (..) expected, got ActiveSupport::HashWithIndifferentAccess(..)" when setting associations with wrapped object added
Actions

Also available in: Atom PDF