Warning while deleting model with no model associated

28 views Asked by At

Hi all and thanks for you help

I have model structure as follows:

Class Model1 {
      public $hasMany = array(
            "Model2" => array (
            "className" => "Model2",
            "foreignKey" => "model1_id",
            "dependent" => TRUE
        )
}

Later on when I try to delete a given Model1 object, if it does not have any Model2 object associated yet, operation outputs a warning telling me that

Invalid argument supplied for foreach() [CORE\Cake\Model\Model.php, line 2648]

Is there any way of avoiding this warning message? I am requesting deletions through JSON AJAX requests and that response is just HTML, avoiding my JSON parser to process it correctly.

1

There are 1 answers

0
cgimeno On

Fixed.

There was an afterFind callback in Model2 that was not returning the results of the query and was returning boolean TRUE instead.

Once this was fixed all started to work

Thanks @maysaghira and @ndm