Hello guys! I'm making a little web-app with Phalcon, but I got a trouble :-(
To simplify my situation, let's say I have
Robots(id, name)
RobotsParentChild(id_parent_robot, id_child_robot)
That relations is just "one level".
In my Controller
when I try to create a new Robot or Updating an existint Robot, I do something like this:
EDIT:
$robot = ($id === null) ? new Robots() : Robots::findFirstById($id);
if ($id === null) {
$robot_parent_child = new RobotsParentChild();
$robot_parent_child->id_child_robot = $robot->id;
} else {
$robot_parent_child = RobotsParentChild::findFirstById($id);
$robot_parent_child->id_child_robot = $id;
}
$robot_parent_child->id_parent_robot = $my_id;
$robot->RobotsParentChild = $robot_parent_child;
Here is the initialize()
method of the RobotsParentChild
Model:
public function initialize()
{
$this->setSchema("myschema");
$this->setSource("robots_parent_child");
$this->belongsTo('id_parent_robot', '\Robots', 'xid', ['alias' => 'Robots']);
$this->belongsTo('id_child_robot', '\Robots', 'xid', ['alias' => 'Robots']);
}
Now it creates correctly, but don't update the id_parent_robot
witht the $my_id
value.