Hello, I have a problem with model relation but i cant get a problem, please help to understand!
namespace Common\Models; use Phalcon\Mvc\Model; class Tags extends Model{
private $id;
private $name;
private $alias_uk;
private $alias_ru;
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @param mixed $alias_uk
*/
public function setAliasUk($alias_uk)
{
$this->alias_uk = $alias_uk;
}
/**
* @param mixed $alias_ru
*/
public function setAliasRu($alias_ru)
{
$this->alias_ru = $alias_ru;
}
public function beforeValidation()
{
$this->id=0;
}
public function initialize()
{
$this->setSource($this->getDI()->get('config')->database->prefix . 'tags');
$this->hasMany('id','\\Common\\Models\\TagsRelations','tag_id');
}
second model
namespace Common\Models; use Phalcon\Mvc\Model; class TagRelations extends Model{
private $id;
private $content_binder_id;
private $tag_id;
/**
* @param mixed $content_binder_id
*/
public function setContentBinderId($content_binder_id)
{
$this->content_binder_id = $content_binder_id;
}
/**
* @param mixed $tag_id
*/
public function setTagId($tag_id)
{
$this->tag_id = $tag_id;
}
public function beforeValidation()
{
$this->id=0;
}
public function initialize()
{
$this->setSource($this->getDI()->get('config')->database->prefix . 'tag_relations');
$this->BelongsTo('tag_id','\\Common\\Models\\Tags','id');
}
}
and in controller
$tag=Tags::findFirst(['id'=>1]); print_r($tag->tagRelations);
and it gives me Access to undefined property Common\Models\Tags::tagRelations but with pure sql works and phsql