5 minutes ago, magicalclick wrote
I think back in the days I played with Cache, which failed miserably on me. I did a one-to-many relationships both way to imitate many-to-many relationship. The end result is it failed without an error, just gave me seemly correct and yet incorrect result.
I've never used Cache but I understand this general problem.
In the relational world you would use a junction table to provide this many-to-many relationship. This works around the fact that relational records can only hold single values and not arrays.
In the object world, you have more options. You can store an array inside of an object. This is great for one-to-many relationships!
What I see often is that the many-to-many is modeled as arrays from each object to the other (a bipartite graph). But this may not be the best thing, as you can get into the problem you mentioned, since each relationship from one to the other is modeled on both objects. So breaking the relationship on one of the two objects could leave the other orphaned.
One alternative is to just implement the equivalent of junction tables in the object model. When you come to think about it, all that a junction table does is describe the set of relationships in a bipartite graph. I don't know that this is the best alternative. But, if you think about it, this problem isn't because the OO model lacks something the relational model has, but because it offers more than the relational model does.
(And it should be noted, this isn't an OODB or NoSQL problem... it's an OO problem. If you are mapping from a SQL database to objects in memory, you may have to consider this issue anyway.)