F
Filamentβ€’6mo ago
ericmp

Relationship repeater not working

I'm creating a form where the users create a new PlayerPreinscription model. This model has many PlayerTutorPreinscription:
// app/Models/Tenant/PlayerPreinscription.php
protected $table = 'player_preinscriptions';

public function tutors(): HasMany
{
return $this->hasMany(PlayerTutorPreinscription::class);
}

// app/Models/Tenant/PlayerTutorPreinscription.php
protected $table = 'player_tutor_preinscriptions';

public function playerPreinscription(): BelongsTo
{
return $this->belongsTo(PlayerPreinscription::class);
}
// app/Models/Tenant/PlayerPreinscription.php
protected $table = 'player_preinscriptions';

public function tutors(): HasMany
{
return $this->hasMany(PlayerTutorPreinscription::class);
}

// app/Models/Tenant/PlayerTutorPreinscription.php
protected $table = 'player_tutor_preinscriptions';

public function playerPreinscription(): BelongsTo
{
return $this->belongsTo(PlayerPreinscription::class);
}
So a person can fill the form with multiple tutors (repeater) for a player. if in the form i put this line, i get the error (see image), otherwise i dont get the error but the items in the repeater are ignored and not saved into the db. ->relationship('tutors') other stuff i already do: in mount method: $this->playerPreinscription = new PlayerPreinscription; i also defined the fn:
protected function getFormModel(): PlayerPreinscription
{
return $this->playerPreinscription;
}
protected function getFormModel(): PlayerPreinscription
{
return $this->playerPreinscription;
}
and in the save method i call save relationships:
$this->form->model($this->playerPreinscription)->saveRelationships();
$this->form->model($this->playerPreinscription)->saveRelationships();
i am missing something? what is happening? ive been strugling for quite a time now... hours
No description
9 Replies
ericmp
ericmpOPβ€’6mo ago
No description
Tetracyclic
Tetracyclicβ€’6mo ago
Interesting. ORDER BY 1, sets it to order by the first column in the SELECT (though its use is discouraged). ORDER BY `1` however is treating 1 as the name of a column.
ericmp
ericmpOPβ€’6mo ago
so it is a bug or im missing something πŸ€” 😒?
Tetracyclic
Tetracyclicβ€’6mo ago
It seems like a bug, but I'm not familiar with the underlying code. Your usecase is pretty simple and seems to fit with the documentation. What happens if you explicitly set the orderColumn() on the repeater?
ericmp
ericmpOPβ€’6mo ago
yeah its just a filament form with some fields and a repeater field, which is a relationship. i tried to check everything out related on how to setup relationships & models in a filament form (v2). i think im not missing anything 1 sec i try
ericmp
ericmpOPβ€’6mo ago
oh god i think 1 sec still testing i think ill make it reorderable false cuz i dont have a order field in my db on that table! i was missing that if i wanted to be reorderable but if i remember well, on v3 i can reorder i mean, without that db field and it just reorders it lets say "in the frontend" interesting im checking it out
Tetracyclic
Tetracyclicβ€’6mo ago
Yeah, if you're reordering a relationship it needs a field it can update. If you just use reorderable(), it defaults to setting orderColumn to sort
ericmp
ericmpOPβ€’6mo ago
true, and that col doesnt exist in my case (,: now im trying to send the form lets see if it stores the relationship lets go!!!!!!! it works perfectly now omg, thanks for enlightening me
Want results from more Discord servers?
Add your server