0

So, I have modeled these entities:

  • Feed
  • Collection

Where I have these relationships:

  • A Feed has a Collection, and a collection alone (1 to 1)
  • A Collection may have any number of Feeds (1 to N)
  • A Collection may have any number of Collections (1 to N)

And what I'm trying to express visually:

  • Collection
    • Collection
      • Feed
    • Collection
      • Feed
      • Feed
    • Feed
    • Feed
  • Collection
    • Feed
    • Feed
    • Feed

enter image description here

How can I return a tree in a table result? Or maybe this is not the right question? I know what I want, but I'm not sure what I should be reading about in order to understand this problem.

Thanks!

nmdias
  • 3,888
  • 5
  • 36
  • 59
  • How do you plan to handle infinite loops, should a collection point to itself? – Tim Biegeleisen Mar 25 '17 at 10:23
  • http://stackoverflow.com/a/5916536/1405981 – Stephan Vierkant Mar 25 '17 at 10:25
  • @TimBiegeleisen infinite loops? I don't understand how I would run into an infinite loop in this scenario. Are you suggesting I don't reference Collection to itself? – nmdias Mar 25 '17 at 10:32
  • Yes, I am. Because then how do you even plan to join? It would require a recursive query, which can be a hassle. – Tim Biegeleisen Mar 25 '17 at 10:34
  • Do we know the maximum depth of the tree? – Lajos Arpad Mar 25 '17 at 10:47
  • Ok, you're making me question these relationships. I am in fact starting with just 1 level deep, but I know for a fact that this will need to go beyond that. If I do break the Collection to different entities (parent, child, ...) wouldn't that be even a bigger hassle to handle? I'd like to be able to insert a feed into any collection without changing the relationships. – nmdias Mar 25 '17 at 10:47
  • @LajosArpad It seems very unlikely to grow past 3 levels deep (root collection not included). I may be wrong. There's an uncertainty factor here. – nmdias Mar 25 '17 at 10:50
  • 1
    http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ – Barmar Mar 25 '17 at 10:58

0 Answers0