0

I've tried to use related manager remove() method with bulk=False but no success.Can anyone tell me what happened and where is mistake ? Thanks. In documentation for remove() is written like below

In order to use remove(obj, bulk=False) I created models like Models to use remove(obj,bulk=False)

Then I tried method itself in interactive shell like bellow:

  1. I've created musician object
  2. created album object with Foreign key to musician object but I didn't save it
  3. I called related manager on musician object to remove album from relation with option bulk=False => I expected that this will call save on my album object and than remove foreign key relation but nothing happened, album wasn't saved nor relation on musician was removed. I expected the final call to album to give me <Album: First album None> and album to be saved in data base but it didn't happen.

interactive shell testing remove(obj,bulk=False)

  1. The same procedure implemented on add(obj, bulk=False) yield expected results add(album2, bulk=False) saved my alabum2 and added reference to musician object

enter image description here

TheBrko
  • 11
  • 3
  • Why do you expect anything different from the output you received? In your first example `album` is an instance that's not been saved to the DB, it wouldn't be part of other queries? – Iain Shelvington Nov 13 '21 at 09:59
  • I expected save() to be called because of bulk=False argument that called save() in add() method I tested before I tried remove() with bulk=False – TheBrko Nov 13 '21 at 11:51
  • But if you call `musician.album_set.all()` before remove() then nothing is returned because you haven't saved the album. If there is nothing to remove then there is nothing to save? – Iain Shelvington Nov 13 '21 at 11:54
  • I didn't call musician.album_set.all() but just musician.album_set without all() part it is relating my musician to album object, check my add() case where I created album2 and didn't save it than I call musician.album_set.add(album2, bulk=False) and it saved album2 to DB and also added relation to the musician – TheBrko Nov 13 '21 at 12:05
  • musician.album_set without all() part returns relatedmanager object not QuerySet – TheBrko Nov 13 '21 at 12:06
  • >>> musician.album_set .RelatedManager object at 0x0000024464BB2EB8> – TheBrko Nov 13 '21 at 12:07

0 Answers0