Hi guys, I have a question regarding relationships, did not spot this in the docs.
If I have the following tables
CREATE TABLE robots (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(70) NOT NULL,
type varchar(32) NOT NULL,
year int(11) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE robots_parts (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
robots_id int(10) NOT NULL,
parts_id int(10) NOT NULL,
created_at DATE NOT NULL,
PRIMARY KEY (id),
KEY robots_id (robots_id),
KEY parts_id (parts_id)
);
with models
class Robots extends \Phalcon\Mvc\Model
{
}
class RobotParts extends \Phalcon\Mvc\Model
{
public function initialize()
{
$this->belongsTo(
'robots_id',
'Robots',
'id'
);
}
}
Is there a way to get RobotParts where Robot type = "droid" in one find call (with loading in the robot details in the RobotParts model if possible) ? eg.
RobotParts::find();
SELECT *
FROM robots_parts
JOIN robots ON robots_parts.robot_id = robots.id
WHERE robots.type = "driod"
Thanks