Having trouble setting up a belongs to many select

i have 3 tables, quality_control_steps, machine_centers,and a join table machine_center_quality_control_step and i can see a row in my table, but i cant seem to get the select working, it should allow me to select from all rows from the quality_control_steps table:
protected static string $relationship = 'qualityControlSteps';

public function form(Form $form): Form
{
return $form
->schema([
Select::make('quality_control_step_id')
->multiple()
->preload()
->relationship('machineCenters', titleAttribute: 'name')
->required()
]);
}
protected static string $relationship = 'qualityControlSteps';

public function form(Form $form): Form
{
return $form
->schema([
Select::make('quality_control_step_id')
->multiple()
->preload()
->relationship('machineCenters', titleAttribute: 'name')
->required()
]);
}
but it shows me a list of the machine centers instead!
No description
Solution:
but it shows me a list of the machine centers instead!
because you asked for that ->relationship('machineCenters', ... filament does not know your set up, neither do I.. I'm going to make the assumption that qualityControlStepsare related to machineCenters. in which case you would need to use ->relationship('machineCenters.qualityControlSteps', 'titleColumn')...
Jump to solution
5 Replies
delboy1978uk
delboy1978ukOP3w ago
if i change the call to relationship() to use qualityControlSteps then the select throws an exception:
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given
because it is checking for that method on the quality control object
Solution
Jordy
Jordy3w ago
but it shows me a list of the machine centers instead!
because you asked for that ->relationship('machineCenters', ... filament does not know your set up, neither do I.. I'm going to make the assumption that qualityControlStepsare related to machineCenters. in which case you would need to use ->relationship('machineCenters.qualityControlSteps', 'titleColumn')
delboy1978uk
delboy1978ukOP3w ago
@Jordy thank you so much! That's exactly all that I needed, machineCenters.qualityControlSteps. Have a great day!
delboy1978uk
delboy1978ukOP3w ago
Oh, only it tries to insert into the quality control steps table, and not the join table?
No description
delboy1978uk
delboy1978ukOP3w ago
but the dropdown looks correct 🙂

Did you find this page helpful?