Giter Site home page Giter Site logo

mongotree's People

Contributors

beyondlex avatar sololance avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

leonalvarez

mongotree's Issues

Error on getting the descendants when working with multiple levels

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.

ancestors & scoping fix

Hi!

I found out that ->ancestors() not working, not sure that it is the right way to fix it, but that patch solves the problem:
in original (lazychaser/laravel-nestedset) QueryBuilder.php inside whereAncestorOf function I change
$inner->whereRaw("{$value} between {$lft} and {$rgt}");
to
$inner->where( "_lft" , "<=", $value );
$inner->where( "_rgt", ">=", $value );

not sure how to pass proper "{$lft}" value from variable here, it's not working after call to wrappedColumns.

With this patch it's possible to get current level ( instead of not working withDepth() ):
$item->ancestors()->get()->count();

Second issue is that when you turn on Scoping, all new root elements saved as [_lft,_rgt] = [1,2] and if parent_id set – everything crashed.

To fix that one I change in TreeTrait.php function applyNestedSetScope():

$query->where($table.'.'.$attribute, '=',
to
$query->where($attribute, '=',

Not sure why mongo do not like this table prefix.

Hope this helps!

missing documentation

Hi!

First of all, thank you for creating this library.

Secondly, could you please add some documention how to install and use this library for new users?

PS I can make a PR if needed.

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.