So i'm havimg problems with model relations , when i try to see all comments from the article ( i tried to var_dump
, yet it seems not to exist , returns null ) see my code :
Articles Modal:
<?php
namespace Frontend\Models;
class Articles extends \Phalcon\Mvc\Model
{
public function getSource()
{
return "news";
}
public function initialize()
{
$this->hasMany("_", "Frontend\Models\ArticleComments", "post");
}
}
Articles Comments Modal:
<?php
namespace Frontend\Models;
class ArticleComments extends \Phalcon\Mvc\Model
{
public function getSource()
{
return "news_comments";
}
public function initialize()
{
$this->belongsTo("post", "Frontend\Models\Articles", "_");
}
}
Atricles Controller :
<?php
namespace Frontend\Controllers;
use Frontend\Models\Articles as Articles,
Frontend\Models\ArticleComments as ArticleComments,
Frontend\Models\ArticleCategories as ArticleCategories;
class ArticlesController extends ControllerBase
{
public function PostAction()
{
$article = Articles::findFirstByUrlrequest($this->dispatcher->getParam(0));
$comments = $article->articlecomments;
$category = ArticleCategories::findFirst($article->category);
$this->view->setVar("article", $article);
$this->view->setVar("comments", $comments);
$this->view->setVar("category", $category);
}
}