use Phalcon\Mvc\Model;
class Robots extends Model
{
public $id;
public $name;
public function initialize()
{
$this->hasManyToMany(
'id',
'RobotsParts',
'robots_id', 'parts_id',
'Parts',
'id'
);
}
}
class Parts extends Model
{
public $id;
public $name;
public function initialize()
{
$this->hasMany(
'id',
'RobotsParts',
'parts_id'
);
}
}
class RobotsParts extends Model
{
public $id;
public $robots_id;
public $parts_id;
public function initialize()
{
$this->belongsTo(
'robots_id',
'Robots',
'id'
);
$this->belongsTo(
'parts_id',
'Parts',
'id'
);
}
}
$robot = Robots::findFirst(1);
foreach ($robot->robotsParts as $robotPart) {
echo $robotPart->parts->name, "\n";
}
https://docs.phalcon.io/en/3.1/db-models-relationships
Error: Access to undefined property ... I also tried "$robot->parts"
At same time $robots->_modelsManager->_aliases has a relation keyed "robots$parts" And this code resolves a realtion correct
$rel = $robot->getModelsManager()->getRelationByAlias(get_class($robot), 'Parts');
and this works (gets the records) $robot->getModelsManager()->getRelationRecords($rel, null, $robot, null)
ver 3.2.2