3

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?

Janusz
  • 187,060
  • 113
  • 301
  • 369
  • Not known with GreenDao so no help there, but I don't totally understand why this is a many-to-many relation? Imagining a tree with branches, and branches with leaves, branches belong to exactly 1 tree and leaves belong to exactly 1 branch. Why is yours different? – Stefan de Bruijn Feb 12 '13 at 16:19
  • Because the leaf is no traditional leaf. A unique leaf can be attached to multiple branches. – Janusz Feb 12 '13 at 17:44

1 Answers1

4

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.

Markus Junginger
  • 6,950
  • 31
  • 52
  • How would such a ClusterLeaf look Codewise? – Janusz Feb 12 '13 at 17:43
  • Properties: id, clusterId, leafId. – Markus Junginger Feb 12 '13 at 17:44
  • So every cluster has a list of ClusterLeafs and every leaf hast a list of clusterleafs. Ok I see I now have to figure out how to query and update that relations. Thanks for the quick response. Any ideas when this joins or this kind of queries will be supported? – Janusz Feb 12 '13 at 21:00
  • Sorry, there's no time line for this feature yet. Btw, there are some breaking changes ahead in 1.3.0: https://plus.google.com/b/103605567853075245881/103605567853075245881/posts/Zqg5ya6N9Nf – Markus Junginger Feb 12 '13 at 22:45
  • 1
    Breaking as in great or in breaking compatibility ;) – Janusz Feb 13 '13 at 15:12