This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

dimti
dimti

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

Firestarter
Firestarter

Пример NestedTree модели:

NestedTree model example: https://github.com/rainlab/forum-plugin/blob/master/models/Channel.php

Last updated

dimti
dimti

Thanks. I learning it

What is


 use \October\Rain\Database\Traits\Sluggable;

За что отвечают эти slug?

Firestarter
Firestarter

Трейт Sluggable для ЧПУ УРЛ. Грубо говоря он позволяет делать из "мама мыла раму" - "mama-myla-ramu" урлы. Смотрите плагины блог и форум для примера.

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.