This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Ran
Ran

category is NestedTree

public $belongsTo = [
        'category' => [
            'Drserv\Vo\Models\Category', 
            'scope' => 'isProject'
        ]
    ];
fields:
    category:
        label: category
        type: relation
        nameFrom: name

this not work for only show child

public function scopeIsProject($query)
 {
      return $query->where('parent_id', '=', 1);
 }

but work like this (parent and child)

 return $query->where('id', '=', 1)->orWhere('parent_id', '=', 1);

plx help Q_Q

Last updated

xchattercho3568
xchattercho3568

Hi there, Did you try this way: return $query->where('parent_id', '=', 1)->get();

Ran
Ran

Hi, xchattercho3568

I tried but still not work

Last updated

xchattercho3568
xchattercho3568

Ok, I thing I got you wrong.

I presume you have a table with columns id and parent_id(this gets values which exist in the first column) and you want to get items from it.

if you want to get the item with id 1: return $query->where('id', '=', 1)->get();

if you want to get the parent of the item with id 1: $currentItem = $query->where('id', '=', 1)->get(); return $query->where('id', '=', $currentItem->parent_id)->get();

if you want to get the children of item with id 1: return $query->where('parent_id', '=', 1)->get();

I hope this helps.

Last updated

Ran
Ran

Thank you xchattercho3568.

I found the problem.

The scope no matter what we return, it will return $query.

So, the problem is the column parent_id.

The relational fields dropdown must have the parents (parent_id = null).

return $query->where('parent_id ', '=', null); → show parents only return $query->where('parent_id ', '=', 1); → show nothing

I think maybe the relational fields dropdown can't show children without its parent

Finally, I try to select columns without parent_id, and it work!!!

just like this return $query->select('id', 'name')->where('parent_id', '=', 1);

Last updated

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.