Room Movement gets a new entry when an Orphan is moved from one room to another.
Now say I wanted to copy an entire Orphanage, complete with all the related entities. Room and Orphan are simple enough to copy - save the new Orphanage to create the ID, and pass it to clones of the Room and Orphan - but entries in Room Movement are slightly more complicated. I would have to maintain a map of old to new IDs for both Orphans and Rooms and do a lookup for each insert. This is simple in this contrived example, but in reality we have a lot of these kinds of relationships under Orphanage, and nested levels of these FK relationships.
Two questions: is this something the ORM should handle? This is a problem not unique to our application, and it seems like with properly configured foreign keys and some sort of "clone strategy" system the ORM should do the heavy lifting and do things in the right order.
If not, is there somewhere where I can read up on this problem and see how other people solved it without creating a big mess of code?
Also asked on Stack Overflow: http://stackoverflow.com/questions/25079025/copying-relational-data-with-non-trivial-relationships