I have costructed a model for a view, "Viewdiscipline", in my postgres database. Whenever I read an instance of the model one variable, $lvl, is NULL even though a pure query through psql gives the correct integer 3. Through the afterFetch() function I have proven that this issue is in/before the model itself.

Quite simply, what is wrong? I have spent most of the day trying to figure this out now and cannot guess any cause.

view:

CREATE VIEW ViewDisciplines AS
       SELECT CharacterID, Discipline, Lvl, URL
       FROM HasDiscipline
       JOIN Disciplines
       ON HasDiscipline.Discipline = Disciplines.Name
;

Model:

<?php
namespace Vokuro\Models;

use Phalcon\Mvc\Model;

/**
 * Vokuro\Models\Viewdisciplines
 *
 */                                
class Viewdisciplines extends Model
{
    /**                                   
     * The character having the discipline
     * @var int
     */
    public $characterId;

    /**                    
     * The disciplines name
     * @var string
     */
    public $discipline;

    /**                     
     * The disciplines level
     * @var int
     */
    public $lvl;

    /**                                
     * URL to info about the discipline
     * @var string
     */
    public $url;

/**                                                       
 * Clarify the relations for easier use in the application
 *
    public function initialize()
    {                                                                                 
        $this->belongsTo('characterId', __NAMESPACE__ . '\Characters', 'characterId');
        $this->belongsTo('discipline', __NAMESPACE__ . '\Disciplines', 'name');

    }

 **
 * debug
 */
    public function afterFetch()
    {                                         
        error_log( "" . (0 + $this->lvl) , 0);
    }
}
?>

Data:

CharacterID = 1, Discipline = Potence, Lvl = 3, URL = test

As I am sure you see i am hacking this together based on vokuro and have yet to change the namespace.