0

I'm starting october and i'm trying also to create a plugin, so maybe noob questions but can't find a working example in some time of searching over the net and the documentation is good as each unit, but lacks "connecting the dots" IMHO... I figured out how to show the related name associated with id using a SimpleTree (maybe not the correct way).

https://www.screencast.com/t/WDYkfPdMQ https://www.screencast.com/t/4NDc3HHDs

frmArea.yaml

fields:
id:
    label: Número
    oc.commentPosition: ''
    span: auto
    disabled: 1
    type: number
area_id:
    label: 'Parente de'
    oc.commentPosition: ''
    emptyOption: 'Sem valor'
    span: auto
    type: dropdown
    nameFrom: area
area:
    label: Área
    span: full
    oc.commentPosition: ''
    type: text

Area.php

<?php namespace JML\Gkb\Models;

use Model;

   /**
 * Model
 */
class Area extends Model


{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SimpleTree;

/*
 * Disable timestamps by default.
 * Remove this line if timestamps are defined in the database table.
 */
public $timestamps = false;


/*
 * Validation
 */
public $rules = [
];

/**
 * @var string The database table used by the model.
 */
public $table = 'jml_gkb_areas';

//Relações

public $hasMany = [
    'area_id' => 'JML\Gkb\Models\Area'
];

/*
public $belongsTo = [
    'area_id' => 'JML\Gkb\Models\Area'
]; */

public function getAreaIdOptions(){
    return Area::all()->listsNested('area', 'id');
}


}

If i create records without choosing any relation to a parent, they get created (the ones on the image for example). If i try to create selecting a parent it get's saving forever... If i try to update une record without parent selecting a parent the same occurs when saving.

During some time or at least at when i clear cache i cant create a record without parent returning a lock timeout after some time... Well, waiting some more i get timeout after 300 seconds... The incremented id gets incremented what means something is thouching the db... I suspect that the query is sending a string where a number is required, but don't know how to achieve that...

Someone can give some help with where to find some related examples or snipets or how to??? And is possible to achive the same result to the list widget ???

TIA

JL

JLongo
  • 49
  • 2
  • 7

1 Answers1

0

Well, solved... Just a digging the SimpleTree trait code to understand how it works... Amazing simple...

<?php namespace JML\Gkb\Models;

use Model;

/**
 * Model
 */
class Area extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SimpleTree;

/*
 * Disable timestamps by default.
 * Remove this line if timestamps are defined in the database table.
 */
public $timestamps = false;
const PARENT_ID = 'area_id';


/*
 * Validation
 */
public $rules = [
];

/**
 * @var string The database table used by the model.
 */
public $table = 'jml_gkb_areas';

//Relações

public function getAreaIdOptions(){

    return Area::all()->listsNested('area', 'id');

}


}

Just need to remove the relations and add

const PARENT_ID = 'area_id';

as that is the column that have the relation with id.

If someone knows the answer how to change the 'area_id' by it's description on Builder's list widget please feel free to comment.

TIA

JLongo
  • 49
  • 2
  • 7