简体   繁体   English

Phalcon关系不起作用

[英]Phalcon relations doesn't work

I trying to create hasMany relation in Phalcon PHP framework. 我试图在Phalcon PHP框架中创建hasMany关系。 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: 尽管存在DB中的预感记录,但结果始终为NULL:

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)

Seems it was just a Browser cache. 似乎只是浏览器缓存。 All works fine. 一切正常。 And I should set the full path to model: Apt\\Models\\TorrentSetItem instead of TorrentSetItem 我应该设置模型的完整路径: Apt \\ Models \\ TorrentSetItem而不是TorrentSetItem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM