F
Filament13mo ago
Oddman

Repeater relationship failing as it returns null

I have this weird error - I have a relationship called "contributors" and a repeater block for my articles. The error is as below:
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in .../vendor/filament/forms/src/Components/Select.php on line 774
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in .../vendor/filament/forms/src/Components/Select.php on line 774
The error stems from this:
Repeater::make('contributors')
->hiddenLabel()
->required(fn (Get $get) => !!$get('published'))
->relationship()
->columns(10)
->reorderable()
->defaultItems(0)
->schema([...])
Repeater::make('contributors')
->hiddenLabel()
->required(fn (Get $get) => !!$get('published'))
->relationship()
->columns(10)
->reorderable()
->defaultItems(0)
->schema([...])
Note that if I remove the relationship() method, it works fine. And here's the relationship defined on my Article model:
public function contributors(): HasMany
{
return $this->hasMany(Contributor::class);
}
public function contributors(): HasMany
{
return $this->hasMany(Contributor::class);
}
I'm not sure what's going on here, as there's nothing wrong with that.
4 Replies
Oddman
OddmanOP13mo ago
Nevermind, I looked at the error more closely - it was due to a poorly-defined relationship on a select dropdown. lol. Weird the error disappeard on that relationship removal though.... 🤔
Helge Sverre
Helge Sverre12mo ago
Not trying to spam, but the solution for those searching for this is most likely the same or related to the scenario i posted here (Repeatable belongstomany with fields that map to pivot columns where one of them is a select that is related to something else): https://discord.com/channels/883083792112300104/1173585043592069191/1187040221917880320
ward
ward9mo ago
I need a fresh link
Want results from more Discord servers?
Add your server