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

Model relations

Hello guys, is it possible to assign more than one condition when defining a relationship between models? Is it possible to do something like this


class Name{

    public function initialize()
    {
            $this->hasMany(Likes::class
            ,
            [
                'id'=>'target_id',
                'type','type_in_other_class'
            ],[ 'alias'=>'likes'])
    }
}

Someone were I work made a table named "likes" and this stores the likes from posts but also from comments. And each row has the type (post,comment) and also the id from the parent class (post,comment). But If an comment & post has the same id it won't work the alias will retrieve everything matching the id and target_id. That is why I want to add multiple conditions

// post.php
class Posts{

    public function initialize()
    {
        $this->hasMany("id",Likes::class,'target_id',['alias'=>'Likes']);
    }
}
// commentsphp
class Comments{

    public function initialize()
    {
        $this->hasMany("id",Likes::class,'target_id',['alias'=>'Likes']);
    }
}