#Repeater ->relationship() inside multiple Group ->relationship() in a form issue

8 messages · Page 1 of 1 (latest)

vale echo
#

Hi! I’m having an issue with relationships in my form.
I have a resource with a form based on my Inscription model.

In this model, I have one student belongTo(Student::class) relationship.

In my Student model, I have two relationships:

AAAs → hasMany(AAA::class)

BBBs → hasMany(BBB::class)

In my form, I have fields like this:

Group::make()
    ->relationship("student")
    ->schema([
        Repeater::make("AAAs")
            ->relationship()
            ...

and later:

/* OK */
Group::make()
    ->relationship("student")
    ->schema([
        Repeater::make("BBBs")
            ->relationship()
            ...

The BBBs repeater displays its data correctly, but the AAAs repeater shows nothing.
However, when I move the AAAs repeater into the same Group as the BBBs one, it works:

/* OK */
Group::make()
    ->relationship("student")
    ->schema([
        Repeater::make("AAAs")
            ->relationship()
            ...
        Repeater::make("BBBs")
            ->relationship()
            ...

I don’t understand why I can’t have them in separate groups.

if i move AAAs repeater Group after BBBs repeater Group, AAAs is working but BBBs dont anymore ...

/* NOT OK */
Group::make()
    ->relationship("student")
    ->schema([
        Repeater::make("BBBs")
            ->relationship()
            ...
            
/* OK */
Group::make()
    ->relationship("student")
    ->schema([
        Repeater::make("AAAs")
            ->relationship()
            ...

If anyone has an idea...

thin flickerBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

wicked fiber
#

You can try giving both Groups a unique key Group::make()->key('student_aaa'), but it might be the saving logic that only allows one Group with the same relation.

vale echo
#

nop ->key doesnt work. And it dont seem to be on the saving logic cause when i add something in my AAAs, repeater, its well saved in the database, but not displayed on the form, only the last Group::make->relationship('student') display the repeater records well ...

vale echo
#

when i add a mutateRelationshipDataBeforeFillUsing on my buggy repeater, i can see my datas, but the repeater doesnt fill ...

Group::make()
    ->relationship("student")
    ->schema([
        Repeater::make("AAAs")
            ->relationship()
            ->schema([
              ...
            ])
->mutateRelationshipDataBeforeFillUsing(function (array $data): array {
          dd($data);
          return $data;
      })
shell quartz
#

Sorry, but what element is this? A Group element having a relationship method?

vale echo
#

I found a way to work around the issue by adding a ->mutateRelationshipDataBeforeFillUsing() on the last Group::make()->relationship('student') in my form to fill the previous Group::make()->relationship('student') blocks.
But it feels a bit weird...
Am I trying to do something too complicated? Was it not meant to be used that way?
Are we only supposed to have only one Group::make()->relationship('') for the same relationship?

Another thing I hadn’t mentioned: each group is in a different tab.