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