I’ve been bashing my head trying to return a list of categories with the categories it inherits from, like this:
Category A
Category A / Category B
Category A / Category B / Category C
From a Table that looks like
_id: 1
name: A
parent: 0
_id: 2
name: B
parent: 1
_id: 3
name: C
parent: 2
Even using a simple for loop, I can’t stop it from returning, A, A/A, A/A, another time I got A, A/B, A/C.
Just to generalize my code (and I deleted it out of frustration) retrieving the records, with a findAll() return an array, going through a for loop using EMongoCriteria match the reference to the primary add to an array, implode it and replace the category name. It only sounded simple… and I’m no good with recursion, I go cross eyed. Is there something I’m missing I just need a hint.
Can you post the code for the loop? Otherwise difficult to guess what the error may be. From your example it would appear that your loop is finding a random parent for A (either A,B, or C) but A is meant to have a null parent in the data (parent: 0).
I finally figured it out I used a simple nested if/else still got the same results, turned out I had to put new MongoID. But it still didn’t make sense why it could find the root category that’s why I thought I was missing something that had to do with the Extension like maybe I opened too many connections at once.