Triagular references #2598
-
Hey there! I'm trying to wrap my head around references and having some difficulty with it. Let's paint a picture. I have three classes: Property, Unit, and Address. In the toy project I'm experimenting with, they look vaguely like this:
In the context of my program, I want to center all of this data on a Properties collection. However, when I generate some data and insert it, this is what the Bson ends up looking like:
As you can see, Address is seeing duplication between Unit and Property. As a result, if I change data in one Address object, the other Address object doesn't see that update. Obviously, we can't have that. What I've been trying to do is to have Unit's Address reference the corresponding Address in the List owned by Property. In my many attempts to get that working, nothing I've tried has been able to correctly reconstruct Unit's address and I'm struggling to find any documentation that could help with it. My aim is to minimize the number of collections I'm creating, so if someone knows how to set this up without creating a new collection I would be deeply appreciative. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
HI, Have a look at DbRef on the website: Kind regards, |
Beta Was this translation helpful? Give feedback.
HI,
I think you need to store your addresses in a separate collections.
This will allow you keep only the id and the collection name in the Adress object.
Have a look at DbRef on the website:
https://www.litedb.org/docs/dbref/
Kind regards,
Alain