Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on getting the descendants when working with multiple levels #5

Open
WILL-I-AM opened this issue Oct 4, 2018 · 0 comments
Open

Comments

@WILL-I-AM
Copy link

Hello,

When working with multiple levels, I can't get only the next descendants.

I am using a mongo db.

Let me explain ...

When working with 2 levels, it all works just fine.

I have the following structure, using 3 levels ( parent, child, grandchild ):

  • parent 1

    • parent 1 child 1
      • parent 1 child 1 grandchild 1
  • parent 2

    • parent 2 child 1
  • parent 3

    • parent 3 child 1
      • parent 3 child 1 grandchild 1
      • parent 3 child 1 grandchild 1

The following structure stores all the parents.
This is ok.

[
{
"_id": "5bb5ac508ac2ef20f4005d26",
"platform": "mobile",
"name": {
"en": "m1",
"ar": "1"
},
"image": {
"en": "1",
"ar": "1"
},
"link": {
"en": "1",
"ar": "1"
},
"parent_id": null,
"_lft": 1,
"_rgt": 6,
"updated_at": "2018-10-04 06:04:35",
"created_at": "2018-10-04 05:59:44"
},
{
"_id": "5bb5ac588ac2ef20f4005d27",
"platform": "mobile",
"name": {
"en": "m2",
"ar": "1"
},
"image": {
"en": "1",
"ar": "1"
},
"link": {
"en": "1",
"ar": "1"
},
"parent_id": null,
"_lft": 7,
"_rgt": 10,
"updated_at": "2018-10-04 06:04:35",
"created_at": "2018-10-04 05:59:52"
},
{
"_id": "5bb5acb48ac2ef20f4005d2d",
"platform": "mobile",
"name": {
"en": "m3",
"ar": "1"
},
"image": {
"en": "1",
"ar": "1"
},
"link": {
"en": "1",
"ar": "1"
},
"parent_id": null,
"_lft": 19,
"_rgt": 24,
"updated_at": "2018-10-04 06:04:35",
"created_at": "2018-10-04 06:01:24"
}
]

The following structure stores one child and one grandchild.
This is wrong.

Within this array, only the model with the _id 5bb5ac988ac2ef20f4005d2b should be returned, because that's the child.

5bb5ad738ac2ef20f4005d37 is the child of 5bb5ac988ac2ef20f4005d2b and this should not be here.

When callind $model->descendants for 5bb5ac508ac2ef20f4005d26 ... I get the following :

[
{
"_id": "5bb5ac988ac2ef20f4005d2b",
"platform": "mobile",
"name": {
"en": "m1 c1",
"ar": "1"
},
"image": {
"en": "1",
"ar": "1"
},
"link": {
"en": "1",
"ar": "1"
},
"parent_id": "5bb5ac508ac2ef20f4005d26",
"_lft": 2,
"_rgt": 5,
"updated_at": "2018-10-04 06:04:35",
"created_at": "2018-10-04 06:00:56"
},
{
"_id": "5bb5ad738ac2ef20f4005d37",
"platform": "mobile",
"name": {
"en": "m1 c1 g1",
"ar": "1"
},
"image": {
"en": "1",
"ar": "1"
},
"link": {
"en": "1",
"ar": "1"
},
"parent_id": "5bb5ac988ac2ef20f4005d2b",
"_lft": 3,
"_rgt": 4,
"updated_at": "2018-10-04 06:04:35",
"created_at": "2018-10-04 06:04:35"
}
]

The grandchild 5bb5ad738ac2ef20f4005d37 should not be returned.

  • parent 1

    • parent 1 child 1
      • parent 1 child 1 grandchild 1
  • parent 2

    • parent 2 child 1
  • parent 3

    • parent 3 child 1
      • parent 3 child 1 grandchild 1
      • parent 3 child 1 grandchild 1

When asking parent 1 for the children, the return should contain only parent 1 child 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant