<?php

/**
 * Created by JSM, based on Reliese Model.
 * Date: {{date}}.
 * --txdGeneratorVersion--{{modelVersion}}--txdGeneratorVersion--
 */

namespace {{namespace}};

use {{parent}};

/**
 * Class {{class}}
 * {{properties}}
 *
 * @package {{namespace}}
 */
class {{class}} extends {{parent}}
{

    public function __construct(array $attributes = array()){

        /** 
         * se l'attributo e' settato prima di invocare il modello, carica automaticamente db_fields, 
         * cosi' da generare i fillable anche nei firstOrNew e simili
         * 
         */
        if(self::$AUTO_LOAD_DB_FIELDS){
            $this->init_db_fields();
        }

        parent::__construct($attributes);

        //andiamo ad impostare nel modello le regole a partire dai vincoli del DB (lunghezza e tipo)
        if(isset($this->db_rules) && is_array($this->db_rules)){

            // supporto legacy per le rules eventualmente definite nell'array della classe estesa
            $rules_modello_esteso = is_array($this->rules) ? $this->rules : [];

            foreach($rules_modello_esteso as $key => $value){
                if(isset($this->db_rules[$key])){
                    $rules_modello_esteso[$key] .= "|".$this->db_rules[$key];
                }
            }

            $this->rules = array_merge($this->db_rules, $rules_modello_esteso);
        }
    }

{{body}}
}
