2014-12-03 97 views
0

我試圖在Phalcon PHP框架中創建hasMany關係。就像在手冊中一樣。Phalcon關係不起作用

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記錄inspite:

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

看來,這只是一個瀏覽器緩存。一切正常。我應該設置模型的完整路徑: Apt \ Models \ TorrentSetItem而不是TorrentSetItem