Improve Collections create and move methods and update documentation
[arvados.git] / sdk / R / R / ArvadosFile.R
index 2257d99bfe9a8ed9d42d18a026fe6974eb20a76c..70bb4450eccca6efd453002dc7a0962c904fb0d0 100644 (file)
@@ -258,18 +258,23 @@ ArvadosFile <- R6::R6Class(
 
         attachToNewParent = function(content, newParent)
         {
-            #Note: We temporary set parents collection to NULL. This will ensure that
-            #      add method doesn't post this file on REST.
+            # We temporary set parents collection to NULL. This will ensure that
+            # add method doesn't post this file on REST.
+            # We also need to set content's collection to NULL because
+            # add method throws exception if we try to add content that already
+            # belongs to a collection.
             parentsCollection <- newParent$getCollection()
+            content$setCollection(NULL, setRecursively = FALSE)
             newParent$setCollection(NULL, setRecursively = FALSE)
             newParent$add(content)
+            content$setCollection(parentsCollection, setRecursively = FALSE)
             newParent$setCollection(parentsCollection, setRecursively = FALSE)
         },
 
         dettachFromCurrentParent = function()
         {
-            #Note: We temporary set parents collection to NULL. This will ensure that
-            #      remove method doesn't remove this file from REST.
+            # We temporary set parents collection to NULL. This will ensure that
+            # remove method doesn't remove this file from REST.
             parent <- private$parent
             parentsCollection <- parent$getCollection()
             parent$setCollection(NULL, setRecursively = FALSE)