BelongsToMany records are not shown in Repeater
Hey 👋
I'd like to use a
Repeater
to present a n:m
relationship. As I found in the documentation I refactored my code and introduced a Pivot model.
Now I tried the Repeater
for the first time and facing following issue:
After I hit save, the records are persisted within the database. When I reload the admin panel, no records are shown in my Repeater
.25 Replies
This is the corresponding code:
Did you change the relationship to
HasMany
, with the pivot model?Yes, I did
still facing this issue :/
When I hit
Save
in the form it's persisted. But why is it not displayed? 💀Something to try, just to see if anything gets loaded into the field:
that looks fine
No console errors btw
I see you have 2 nested repeaters, and both are using
->relationship()
. Could this be the issue? The 1st level relationship is loading but the 2nd level isn't?I use the same pattern at another place as well but there it's 1:n instead of n:m.
Can you share your Room and Season models? To understand the relationships a bit better...
Sure, give me a moment
I removed unneccessary variables and methods.
FWIW I'm having the same (or a very similar) issue. Here's a repo with minimal code to reproduce it
https://github.com/sprtk-ches/laravel-filament
Another thing I notice is that some relationships are saved in the
form->validate()
step. Not sure if this is intentional but it looks weird and I'm getting the following error
Note that it doesn't pick up the column names in the where/and
clause@pboivin should we get someone from the core team into this? 🤔
Probably... I think it's a bit beyond my depth. The only thing I can see is that the relationship to the pivot model is still
seasons
. Not sure if Filament relies on that name internally. Have you tried roomSeasons
, to match the pivot?
Not sure if anyone is available at the minute but I'll try to tag someone in.I did not, let me try that first before tagging the team.
No that did not help :/
that's the current form
I could be wrong but I’m fairly sure the name of the repeater shouldn’t be the same name as the relationship.
I'll check, give me a moment.
You.
are.
fucking.
genious.
🫶
I wanted to record it so you can see the behaviour and it worked after renaming the repeater. 😂
That is weird, because Filament will use the Repeater name as the relationship name, if you don't specify the relationship name.
https://filamentphp.com/docs/3.x/forms/fields/repeater#integrating-with-an-eloquent-relationship
Yea. I think OP was creating a double nesting though. In this case.
Maybe there‘s an unknown issue when using nested Repeaters with relationship name and name being the same when the relation is an n:m 😂
Maybe.
I think I'll try to reproduce in a few days and if it occurs in a fresh repository as well, I'll open a issue on GitHub.