Cphalcon: [BUG]: Delete related records without considering additional conditions/params

Created on 1 Jul 2020  路  3Comments  路  Source: phalcon/cphalcon

Hi there. I found a bug (not sure its a bug or this is right behavior)
Its somehow connected with relations. When i delete the parent model, related one (with ACTION_CASCADE foreign key) will be deleted too but without conditions/params (if we have). Lets describe well with the example:

My Model

class Musicians extends \Phalcon\Mvc\Model
{
    public function initialize()
    {
        $this->hasMany('id', 'Models\Pictures', 'parent_id', [
            'foreignKey' => [
                'action' => \Phalcon\Mvc\Model\Relation::ACTION_CASCADE,
            ],
            'alias' => 'Gallery',
            'params' => [
                'conditions' => 'type={type:str} AND subtype={subtype:str}',
                'bind' => [
                    'type' => get_class($this),
                    'subtype' => 'gallery'
                ]
            ]
        ]);
    }  
}

Pictures table columns are (for example): parent_id | type | subtype:

  • 1 | Models\Musicians | gallery
  • 1 | ModelsArticles | gallery

Now if i do this:

$musician = \Models\Musicians::findFirst(1);
$musician->delete(); 

... will be deleted all records from picture with parent_id=1 (without extended conditions - type and subtype)

Expected behavior
To delete only records with parent_id, type and subtype (together).

Sorry for my English skills. Hope you understand me.

Details

  • Phalcon version: 4.0.6
  • PHP Version: 7.3.10
  • Server: Apache
  • Mysql
4.1.0 bug

All 3 comments

I can verify this, the params option is completely ignored.

https://github.com/phalcon/cphalcon/blob/634e7233a86780c9509614a8d835b188c8be76e5/phalcon/Mvc/Model.zep#L3362-L3367

The conditions option used here is neither documented, nor used anywhere else. (It should be inside params, but even on its own it wouldn't be enough.)

This is a very high priority bug as the probability of a possible data loss is almost certain.
I am going to fix this ASAP.

U great. Thanks 馃憤

Resolved in #15126

Was this page helpful?
0 / 5 - 0 ratings