morphToMany issue with RelationManager
Hi,
i have a problem with the relation manager when i try to associate a Product Model to a Order Model, the query give me an error "Column not found: 1054 Unknown column 'products.order_id' in 'field list'"
what am I doing wrong?
Thanks
This is my model code:
i have a problem with the relation manager when i try to associate a Product Model to a Order Model, the query give me an error "Column not found: 1054 Unknown column 'products.order_id' in 'field list'"
what am I doing wrong?
Thanks
This is my model code:
class Order extends Model
{
public function products()
{
return $this->morphedByMany(Product::class, 'order_item');
}
}class Order extends Model
{
public function products()
{
return $this->morphedByMany(Product::class, 'order_item');
}
}class Product extends Model implements Purchasable
{
public function orders()
{
return $this->morphToMany(Order::class, 'order_item');
}
}class Product extends Model implements Purchasable
{
public function orders()
{
return $this->morphToMany(Order::class, 'order_item');
}
}class OrderItem extends Model
{
public function order_item()
{
return $this->morphTo();
}
}class OrderItem extends Model
{
public function order_item()
{
return $this->morphTo();
}
}class ProductsRelationManager extends RelationManager
{
protected static string $relationship = 'products';
protected static ?string $inverseRelationship = 'orders';
public function form(Form $form): Form
{
return $form
->schema([]);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('order_id')
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\AssociateAction::make()->form(fn (AssociateAction $action): array => [
$action->getRecordSelect(),
Forms\Components\Select::make('name')
->options(Product::all()->pluck('name', 'id'))
->required(),
]),
])
->actions([
Tables\Actions\DissociateAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DissociateBulkAction::make(),
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}class ProductsRelationManager extends RelationManager
{
protected static string $relationship = 'products';
protected static ?string $inverseRelationship = 'orders';
public function form(Form $form): Form
{
return $form
->schema([]);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('order_id')
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\AssociateAction::make()->form(fn (AssociateAction $action): array => [
$action->getRecordSelect(),
Forms\Components\Select::make('name')
->options(Product::all()->pluck('name', 'id'))
->required(),
]),
])
->actions([
Tables\Actions\DissociateAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DissociateBulkAction::make(),
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}