GreenDao Many for many relationships
I am using Greendao for my database mapping in Android. Everything works fine so far.
But now I have the following problem:
I have cluster and sheet objects. The cluster contains many sheet objects. If a cluster is scaled up, it can split into more clusters and more tiles. This is not a strict relation to a tree, because a large cluster has many leaves, but a small cluster may have a subset of those leaves.
Basically a cluster has many leaves, but the leaves are also in multiple clusters, since the leaf ID is unique and the relation to the cluster is stored in the leaf, can a leaf only be in one cluster on the right?
The greendao homepage says that many, many relationships are possible, but I cannot figure out how to model this relationship.
Is it possible to model such a relationship or is the data structure a problem for GreenDao?
source to share
Start with a quote from the docs :
As long as greenDAO doesn't support n: m relationships right now, you can model the join table as a separate entity. In practice, you often have "relation objects" with additional properties, so you may want one way or another. In future releases greenDAO may introduce direct support for n: m relationships.
So, in your case, you need to simulate an entity, that is, between cluster and leaf. Let's call this ClusterLeaf object. For efficiently querying sheets for a cluster, I would suggest raw queries as QueryBuilder doesn't support joins yet.
source to share