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

Category isn't getting related video blogs?

I am trying to get category related video blogs by below code but i get nothing in vardump?

    $category = VideoBlogCategoryModel::findFirst(1); // This returns category successfully and there are many video   blogs having this category linked
    var_dump($category->getVideoBlogs());exit; 

VideoBlogModel.php

 public function initialize(){

    // Run base initialize code
    parent::initialize();

    // Configure Relation with VideoBlogCategoryModel
    $this->belongsTo('category_id', VideoBlogCategoryModel::class, 'id', array(
        'alias' => 'videoCategory',
        'foreignKey' => true
    ));
}
public function getVideoCategory(){
    return $this->videoCategory;
}

public function setVideoCategory($videoCategory){
    $this->videoCategory = $videoCategory;
}

VideoBlogCategoryModel.php

 public function initialize(){

    // Run base initialize code
    parent::initialize();

    // Configure relation with VideoBlogModel
    $this->hasMany('id', VideoBlogModel::class, 'category_id', array(
        'alias' => 'videoBlogs',
        'foreignKey' => true,
        'cxAction' => static::ACTION_CASCADE_DELETE
    ));
}
   public function getVideoBlogs(){
    return $this->videoBlogs;
}

public function setVideoBlogs($videoBlogs){
    $this->videoBlogs = $videoBlogs;
}

Thanks

You added getter and you are returning videoBlogs property which will be always null no matter what you do. You need to ust here return $this->getRelated('videoBlogs') or remove getter and use magic getter.

public function getVideoBlogs(){ //return $this->videoBlogs; $this->getRelated('videoBlogs'); }

Changed code to the above now it's returning NULL

@Wojciech Ślawski any update on this ?