staudenmeir / laravel-adjacency-list

Recursive Laravel Eloquent relationships with CTEs
MIT License
1.36k stars 110 forks source link

Undefined property: stdClass::$custom_path #250

Closed loveshiun closed 3 months ago

loveshiun commented 3 months ago

I tried to eager load (nested) relations with just some columns including path but not all the custom paths, I got Undefined property: stdClass::$custom_path.

I use getCustomPaths() which includes custom_path

When in laravel-adjacency-list/src/Eloquent/Traits/BuildsAdjacencyListQueries.php getModels()

$path = $this->model->getPathName(); // here is "path". I tried to eager load the column

if (isset($items[0]->$path)) { // has the value

    ...
    foreach ($this->model->getCustomPaths() as $path) { // I also defined other custom paths in the model, but the columns are not all eager loaded for some queries
        $this->replacePathSeparator(
            ...

and then the replacePathSeparator() may read and use $item->$path.

Is it possible not to include custom paths when including path?

staudenmeir commented 3 months ago

Hi @loveshiun,

I tried to eager load (nested) relations with just some columns including path but not all the custom paths, I got Undefined property: stdClass::$custom_path.

What does your query look like?

loveshiun commented 3 months ago

When I tried to isolate the problem, and tested by using this package only, it worked correctly; the error cannot be reproduced. Maybe other parts of my program caused the error.

It looks okay. This issue can be closed.

Thank you!