如何从 Phalcon 中的相关表中获取数据?

How to get datas from related tables in Phalcon?

我的结构与 phalcon 模型文档中的结构完全相同: http://docs.phalconphp.com/en/latest/_images/eer-1.png

在模型中,我实现了以下 hasmany 和 belongsto 行:

机器人型号:

class Robots extends \Phalcon\Mvc\Model
{
    public $id;
    public $name;
    public function initialize(){
        $this->hasMany("id", "RobotsParts", "robots_id");
    }
}

零件型号:

class Parts extends \Phalcon\Mvc\Model
{
    public $id;
    public $name;
    public function initialize(){
        $this->hasMany("id", "RobotsParts", "parts_id");
    }
}

RobotParts 型号:

class RobotsParts extends \Phalcon\Mvc\Model
{
    public $id;
    public $robots_id;
    public $parts_id;
    public function initialize(){
        $this->belongsTo("robots_id", "Robots", "id");
        $this->belongsTo("parts_id", "Parts", "id");
    }
} 

此时我希望通过调用 RobotParts::find() 获取所有数据,但我只能看到 ID。 为了进行调试,我转储了,但只找到了 ids:(

$rp = RobotParts::find()->toArray();
var_dump($rp);

我想得到这样的结果:

array (size=1)
  0 => 
    array (size=7)
      'id' => int '1' (length=1)
      'robots_id' => int '4' (length=1)
          'name'  => string 'r2d2' (length=4)
          'type'  => string 'droid' (length=5)
          'year'  => int '2184' (length=4)
      'parts_id' => int '4' (length=1)
          'name'  => string 'wheel' (length=5)

var_dump() 不包含相关表,需要从视图中引用它,例如:

robots.RobotParts.name