<?php

class StranasNewTargetInstansi extends \Phalcon\Mvc\Model
{

    /**
     * Initialize method for model.
     */
    public function initialize() {
        $this->setSchema("jaga");
        $this->setSource("stranas_target_instansi");
        $this->hasMany("id", "StranasNewMaster", "id_target");
        $this->belongsTo("id_level1", "StranasNewHierarchy", "id", ['alias' => 'level1']);
        $this->belongsTo("id_level2", "StranasNewHierarchy", "id", ['alias' => 'level2']);
        $this->belongsTo("id_level3", "StranasNewHierarchy", "id", ['alias' => 'level3']);
        $this->belongsTo("id_level4", "StranasNewHierarchy", "id", ['alias' => 'level4']);
    }

    public function getDetail($columns = null)
    {
        
        // return $this->StranasNewMaster->toArray(['instansi']);
        $result = parent::toArray($columns);
        $result['instansi'] = $this->StranasNewMaster;

        return $result;
    }
    
    public function toArray($columns = null)
    {
        $result = parent::toArray($columns);
        $result['instansi'] = $this->StranasNewMaster;
        $result['level1'] = empty($this->level1) ? null : $this->level1->toArraySimple();
        $result['level2'] = empty($this->level2) ? null : $this->level2->toArraySimple();
        $result['level3'] = empty($this->level3) ? null : $this->level3->toArraySimple();
        $result['level4'] = empty($this->level4) ? null : $this->level4->toArraySimple();

        return $result;
    }

    public function toDetail($columns = null)
    {
        $result = parent::toArray($columns);
        $result['instansi'] = $this->StranasNewMaster;

        return $result;
    }
}
