CakePHP 3 - array_merge(): Argument #2 is not an array

I have an odd error in a CakePHP 3 Application I am developing and I can't figure what the issue is.The application and issue is as follows:

  1. I have a Wishlist
  2. That Wishlist can have many Wishlist Items
  3. I am using Angular/Ajax to make a call and delete a WishlistItem
  4. This does not work and it returns the following error:

    array_merge(): Argument #2 is not an array 
    /­vendor/­cakephp/­cakephp/­src/­ORM/­Association/­DependentDeleteTrait.php 54
  5. The WishlistItemsController.php in question is:

    public function delete($id = null) {
        $this->autoRender = false;
        $this->request->allowMethod(['post', 'delete']);
        $wishlistItem = $this->WishlistItems->get($id);
        if ($this->WishlistItems->delete($wishlistItem)) {
            echo json_encode(['message' => ['type' => 'success', 'text' => 'This wishlist item has been deleted successfully']]);
        else {
            echo json_encode(['message' => ['type' => 'error', 'text' => 'This wishlist item could not be deleted']]);
  6. The Wishlist Items have no dependents and the error is coming from this file line 54

  7. My table files look like this:

    $this->hasMany('WishlistItems', [
        'foreignKey' => 'wishlist_id',
        'dependent' => true,
        'cascadeCallbacks' => true,
    $this->belongsTo('Wishlists', [
        'foreignKey' => 'wishlist_id'
    $this->addBehavior('CounterCache', [
        'Wishlists' => ['items_count']

I cannot understand why cascadeDelete function is being used when this Table does not have any dependents.


Whoops\Exception\ErrorException thrown with message "array_merge(): Argument #2 is not an array"

#15 Whoops\Exception\ErrorException in /var/www/
#14 Whoops\Run:handleError in /var/www/
#13 Gourmet\Whoops\Error\WhoopsHandler:_displayError in /var/www/
#12 Cake\Error\BaseErrorHandler:handleError in <#unknown>:0
#11 array_merge in /var/www/
#10 Cake\ORM\Association\HasMany:cascadeDelete in /var/www/
#9 Cake\ORM\AssociationCollection:cascadeDelete in /var/www/
#8 Cake\ORM\Table:_processDelete in /var/www/
#7 Cake\ORM\Table:Cake\ORM\{closure} in /var/www/
#6 Cake\Database\Connection:transactional in /var/www/
#5 Cake\ORM\Table:delete in /var/www/
#4 App\Controller\WishlistItemsController:delete in <#unknown>:0
#3 call_user_func_array in /var/www/
#2 Cake\Controller\Controller:invokeAction in /var/www/
#1 Cake\Routing\Dispatcher:_invoke in /var/www/
#0 Cake\Routing\Dispatcher:dispatch in /var/www/


If there were really only BelongsTo associations on the table object where you are calling delete(), then such a control flow should never happen, so there need to be more associations defined from elsewhere.

Given that the Ratings.Ratable behavior belongs to dereuromark/cakephp-ratings, I'd suspect that the problem are the conditions that are being defined for the HasMany association that the behavior adds to the table:

$this->_table->hasMany('Ratings', [
        'className' => $this->_config['rateClass'],
        'foreignKey' => $this->_config['foreignKey'],
        'unique' => true,

        'conditions' => '', // <<<<<< There it is

        'fields' => '',
        'dependent' => true,
        //'table' => 'sandbox_ratings'

That value ends up being passed to array_merge() as the second argument in DependentDeleteTrait::cascadeDelete(), hence the error.

So, that's a bug in the plugin, and I'd suggest that you report it. As a quick workaround, you could overwrite the conditions in your table class, like


Need Your Help

SQL grouping issue

sql oracle group-by

Neea a help with grouping in sql.