saade / filament-adjacency-list

A Filament package to manage adjacency lists (aka trees).
https://filamentphp.com/plugins/saade-adjacency-list
MIT License
74 stars 13 forks source link

add relationships support #3

Closed saade closed 7 months ago

saade commented 1 year ago

waiting on https://github.com/staudenmeir/laravel-adjacency-list/issues/186 to support nested relationships.

atmonshi commented 11 months ago

hi @saade, ✌

I've been testing this branch, and was getting the error: Undefined array key "name"

and this is my $getState() looks like:

tree-1

after long debugging, I found that you do:

$record->only([$record->getKeyName(), ...$record->getFillable()]);

in HasRelationships.php

and my models don't have 'fillable' on it. not sure but I think it's common to do $guarded = [] from what I've seen :), personally, I disable it from the serviceProvifer on all models.

is it possible maybe use $record->toArray()' or maybe add new property:$treeFillable = []`.

saade commented 10 months ago

Hey @atmonshi,

Are you still using this branch? Could you test to see if it works for you now? If yes, relationship support is ready =)

atmonshi commented 10 months ago

Thank you @saade for amazing work

I am getting weird thing, not sure if its related to my setup or not

Menus Model:

public function items()
    {
        return $this->hasMany(MenusItems::class, 'menu_id', 'id')->orderBy('ordering');
    }

MenusItems Model:

public function children()
    {
        return $this->hasMany(MenusItems::class, 'menu_id', 'id')->orderBy('ordering');
    }

MenuResource Form:

AdjacencyList::make('items')
       ->relationship('items')
       ->labelKey('created_by')
       ->childrenKey('children')
       ->form([
           TextInput::make('app_code')->required(),
       ]),

but I got duplicated items one for the actual row, and one for its children's even if it doesn't have any.

adj-1

adj-4

saade commented 10 months ago

Yeah, noticed that today,

TBH, I'm willing to keep this package json-only and wait for someone (maybe @cheesegrits) to work on the relationship feature (since my implementation will probably not work for graphs too).

I'm literally exhausted trying to make this work, (not only the relationship, but working with filament actions to make the correct parameter resolving inside the modal). Maybe i'm biased towards some business logic that i can't think of another way to make this work as expected. I've already rewritten the relationship support like 5 times, and always got stuck at some problem.

Sorry to disappoint you guys. (Glad i didnt made this a paid package)

atmonshi commented 10 months ago

Don't worry about it :) I wanted to make sure I had the correct setup. But now I'll try to take a shot at this and see if I can do something in the next few days.

thank you again.