37 lines
875 B
PHP
37 lines
875 B
PHP
|
<?php
|
||
|
namespace Contabilidad;
|
||
|
|
||
|
use ProVM\Common\Alias\Model;
|
||
|
|
||
|
/**
|
||
|
* @property int $id
|
||
|
* @property string $nombre
|
||
|
* @property Categoria $categoria_id
|
||
|
*/
|
||
|
class Cuenta extends Model {
|
||
|
public static $_table = 'cuentas';
|
||
|
protected static $fields = ['nombre', 'categoria_id'];
|
||
|
|
||
|
protected $categoria;
|
||
|
public function categoria() {
|
||
|
if ($this->categoria === null) {
|
||
|
$this->categoria = $this->childOf(Categoria::class, [Model::SELF_KEY => 'categoria_id']);
|
||
|
}
|
||
|
return $this->categoria;
|
||
|
}
|
||
|
|
||
|
protected $entradas;
|
||
|
public function entradas() {
|
||
|
if ($this->entradas === null) {
|
||
|
$this->entradas = $this->parentOf(Entrada::class, [Model::CHILD_KEY => 'cuenta_id']);
|
||
|
}
|
||
|
return $this->entradas;
|
||
|
}
|
||
|
|
||
|
public function toArray(): array {
|
||
|
$arr = parent::toArray();
|
||
|
$arr['categoria'] = $this->categoria()->toArray();
|
||
|
return $arr;
|
||
|
}
|
||
|
}
|