Hi
I try to create belongsTo relation on self model (Category model belongsTo Category model).
And laravel-framework generate that query for this reason:
select
dimti_spim_categories.*, (select name from dimti_spim_categories where dimti_spim_categories.parent_id = dimti_spim_categories.id) as category_parent from dimti_spim_categories order by id desc limit 20 offset 0
My model:
<?php namespace Dimti\Spim\Models;
use Model;
class Category extends Model
{
...
public $belongsTo = [
'category_parent' => ['\Dimti\Spim\Models\Category', 'foreignKey' => 'parent_id'],
];
...
}
Of course that sql-query, generated by Illuminate Grammar not working. Parent_id attribute is null in all records.
I need that for viewed in List widget. My category/columns.yaml config is:
columns:
id:
label: ID
searchable: true
category_parent:
label: Родительская категория
relation: category_parent
select: name
name:
label: Название
How to fix it or how to use best practice for relation on self model with parent_id key and showing parent record name in list widget? May be that bug in laravel?
Last updated