Phalcon关系不起作用

时间:2014-12-03 18:51:00

标签: php phalcon

我尝试在Phalcon PHP框架中创建 hasMany 关系。就像在手册中一样。

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')
        );
    }

}

当我尝试获取相关记录时:

$set = TorrentSet::findFirstById(1);

var_dump($set->torrentSetItem); 

结果总是为NULL,尽管DB中的presense记录:

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)

1 个答案:

答案 0 :(得分:1)

似乎它只是一个浏览器缓存。一切正常。我应该设置模型的完整路径: Apt \ Models \ TorrentSetItem 而不是 TorrentSetItem