Hello everybody !
It is quite possible that I got something completely wrong, but I spent some time on google and didn't find any answer to my problem.
I have two models (User, Text). One User has many Text. I'm trying to access the User pseudonym through the Text. Here is my code :
<?php
// User model
use Phalcon\Mvc\Model;
class User extends Model
{
/**
* @var integer
*/
protected $id;
/**
* @var string
*/
protected $pseudonym;
public function initialize()
{
$this->hasMany(
"id",
"Text",
"user_id"
);
}
// Here some accessors (including getPseudonym() )
}
// Text model
use Phalcon\Mvc\Model;
class Text extends Model
{
/**
* @var integer
*/
protected $id;
public function initialize()
{
$this->belongsTo(
"user_id",
"User",
"id"
);
}
// Here some accessors
}
// In the controller
public function indexAction()
{
$blogArticle = Text::findFirst();
$pseudonym = $blogArticle->user->pseudonym;
}
The 'pseudonym' variable on the last line is NULL whereas it should be a string.
Thank you for your time and help, and please forgive my English, for I am French...