Skip to content

Saving a model fails if there's too many children in a touches relationship #39259

@creekorful

Description

@creekorful
  • Laravel Version: 8.49.2
  • PHP Version: 8.0.11
  • Database Driver & Version: mysql

Description:

When saving a model that define touches, the save fails with:

SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders

If there's too many children in the touched relation.

Steps To Reproduce:

  • Have a model with relationship

  • Have an high number of child in the relationship.

  • Define the relationship in $touches.

  • Update the parent and then save it: the request will fails with the given error message.

Steps to Resolve

I think we need to chunk the $ids before updating, to make sure we doesn't reach the placeholder limit. See:

$this->getRelated()->newQueryWithoutRelationships()->whereIn($key, $ids)->update($columns);

Notes

In our case, this happens with a BelongsToMany relationship but I suppose other relationship may be affected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions