We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Polimorphic Relation

Hello, What is the proper way of doing Polimorphyc relation between two Models where the second model is connected with two fields id and alias. When i try the below code, it produces following sql for image table:

class Property extends Model
{
    public $id;
    //conection 
    public $alias = "prop";
    public function initialize()
    {   
        $this->hasMany(array("id","alias"),"Image",array("tbl_id","tbl_name"));
    }
}

the image model:

class Image extends Model
{
    public $id;
    public $tbl_name;
    public $tbl_id;
    public $image;
}

sql:

SELECT `images`.`id`, `images`.`tbl_name`, `images`.`tbl_id`, `images`.`image` FROM `images` WHERE `images`.`tbl_id` = NULL AND `images`.`tbl_name` = NULL

As you can see the tbl_id and tbl_name are equal to NULL insted of the value of the $id and the $alias filed which is "prop" Am I doing sth wrong or ther is a bug in file: /phalcon/mvc/model/manager.zep - getRelationRecords - line 1282 shoud be

placeholders["APR" . refPosition] = record->readAttribute(fields[refPosition])