After having fought with my database schema and the phalcon orm for 2 hours because of a typo. I deceided to make a small add-on that would avoid this ( and maybe save other phalcon newbies a lot of time :) ) This class will override all relationship related methods (belongsTo & co) in \Phalcon\Mvc\Model and will check if the fields/objects you are requesting in the parameters really exist.

So for example:

class customer extends BaseModel {
    protected $id;
    protected $siteid;

    public function initialize()
        $this->belongsTo('siteid', 'Sites', '5id');

The only difference is that we are inheriting from BaseModel and not \Phalcon\Mvc\Model.

Now suppose you made a typo because your cat also wanted to code while you where working. And '5id' actually need to be 'id'. This will trigger a warning

Cannot find field 5id used by belongsTo in Object Sites

All fields and objects give to belongsTo,hasManyToMany,hasMany and hasOne are checked.

Please check for the code

For now this class is just echo'ing the errors which seems rather ugly, is there somekind of phalcon specific logging class I could use ? Also I would like to be able to disable all checks when the site is running in production (is this already in phalcon ?). Suggestions welcome..