Question

I use Greendao for my database mapping in Android. So far everything works great.

But now I have the following problem:

I have a Cluster and leaf Objects. A cluster contains many leaf objects. If a cluster is zoomed it can split up in more clusters and more leafs. This is not a strict tree relationship it is more that a big cluster has a lots of leafs but a small cluster can have a subset of this leafs.

Basically a cluster has many leafs but leafs also are in multiple clusters, since the id of a leaf is unique and the relation to the cluster is saved in the leaf a leaf can only be in one cluster right?

The greendao homepage states that many to many relations are possible but how i can't get my head around it how to model this relation.

Is it possible to model such a relation or is the data structure a problem for GreenDao?

Was it helpful?

Solution

Let's start with a quote from the docs:

While greenDAO does not support n:m relations directly as of now, you can model the join table as a separate entity. In practice, you often have “relation entities” with additional properties, so you might want to do so anyway. In future releases, greenDAO might introduce direct support of n:m relations.

So, in your case you have to model an entity, that is between Cluster and Leaf. Let's call this entity ClusterLeaf. To query leafs for a cluster efficiently, I'd suggest raw queries because the QueryBuilder does not support joins yet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top