I trying to create hasMany relation in Phalcon PHP framework. Just as in a manual.
class TorrentSet extends \Phalcon\Mvc\Model
{
public function initialize()
{
$this->hasMany(
"id",
"TorrentSetItem",
"set_id"
);
}
}
class TorrentSetItem extends \Phalcon\Mvc\Model
{
public function initialize()
{
$this->belongsTo('set_id', 'TorrentSet', 'id',
array('alias' => 'set')
);
}
}
When I try to get related records:
$set = TorrentSet::findFirstById(1);
var_dump($set->torrentSetItem);
And the result is always NULL, inspite of the presense records in DB:
mysql> select * from torrent_set where id = 1;
+----+------------+
| id | title |
+----+------------+
| 1 | Film |
+----+------------+
1 row in set (0.00 sec)
mysql> select * from torrent_set_item where set_id = 1;
+----+--------+---------+-----+
| id | set_id | attr_id | pos |
+----+--------+---------+-----+
| 1 | 1 | 2 | 0 |
| 2 | 1 | 1 | 1 |
+----+--------+---------+-----+
2 rows in set (0.01 sec)