Here's how I see the situation. You have Robots that are made of parts. Then you have ProductionOrders that tell the factory which parts to produce. When I delete a Robot I want to delete all it's parts, hence ACTION_CASCADE. But, if the part is referenced by a production order it cannot be deleted, hence foreignKey with message. In this case the Robot should not be deleted either since the cascade is unsuccessful.

But when I do $robot->delete() the Robot gets deleted and its Parts remain in the database. Is this the expected behaviour in phalcon?

class Robots extends Model {
    public function initialize() {
        $this->hasMany('id', 'Parts', 'robotId', array(
            'alias' => 'parts',
            'foreignKey' => array(
                'action' => Relation::ACTION_CASCADE,
                'message' => 'Robot cannot be deleted because it has parts'
            )
        ));
    }
}

class Parts extends Model {
    public function initialize() {
        $this->belongsTo('robotId', 'Robots', 'id', array(
            'alias' => 'robot'
        ));

        $this->hasMany('id', 'ProductionOrders', 'partId', array(
            'alias' => 'productionOrders',
            'foreignKey' => array(
                'message' => 'Part cannot be deleted because it\'s going to be produced'
            )
        ));
    }
}

class ProductionOrders extends Model {
    public function initialize() {
      $this->belongsTo('partId', 'Parts', 'id', array(
          'alias' => 'part'
      ));
    }
}