Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloning complex model relationships #175

Closed
fabianallendorf opened this issue Jul 2, 2020 · 4 comments
Closed

Cloning complex model relationships #175

fabianallendorf opened this issue Jul 2, 2020 · 4 comments
Assignees

Comments

@fabianallendorf
Copy link

Is your feature request related to a problem? Please describe.
I have a complex database structure. Its better to be explained using an example:

class House(CloneMixin, models.Model):
   _clone_many_to_one_or_one_to_many_fields = ["rooms", "furniture"]  # either this

class Room(CloneMixin, models.Model):
   _clone_many_to_one_or_one_to_many_fields = ["furniture"]  # or this?

  house = models.ForeignKey(House, related_name="rooms")

class Furniture(CloneMixin, models.Model):
  house = models.ForeignKey(House, related_name="furniture")
  room = models.ForeignKey(Room, related_name="furniture")

Lets say I want to clone a House object which has a few Room and Furniture objects. The problem arises that, when it clones a Furniture object, it will update the foreign key to house but not room. Or when I clone Room it will update the room foreign key but not the house foreign key.

This way I can imagine to end up in a state where cloned Furniture objects exist twice with either a reference to Room or House missing.

Describe the solution you'd like
I would want to have a mechanism were I can tell the Furniture during cloning that it has to update both foreign keys accordingly.

Describe alternatives you've considered
Passing a map of old and new instances down the foreign key relationship path which lower level objects can access to update every foreign key.

@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.70. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@jackton1 jackton1 self-assigned this Aug 16, 2020
@jackton1
Copy link
Member

jackton1 commented Apr 10, 2021

@fabianallendorf This might be resolved now but I'll setup a test to replicate.

Giving the current design

	       House 1 name (My House)                       House 2 name (My House)
 	            |                       Clone                   |
(1st room)	  /   \ (2nd room)                     (1st room)  /  \ (2nd room) 
          Room 1  Room 2               =----->             Room 3  Room 4 
(chair)    /        \ (chair)                      (chair) /        \ (chair)
       Chair 1    Chair 2                               Chair 3    Chair 4

It would be helpful to fully understand your use case would you like to share the same
house instance / room / or furniture

@jackton1
Copy link
Member

@fabianallendorf Let me know if this is still a blocker ?

@jackton1
Copy link
Member

jackton1 commented Apr 25, 2021

@fabianallendorf closing this issue for now let me know if this is still a requirement using the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants