bolt / core

🧿 Bolt 5 core
https://boltcms.io
MIT License
542 stars 159 forks source link

Removing a relation from content throws error on save #3486

Closed doenietzomoeilijk closed 12 months ago

doenietzomoeilijk commented 12 months ago

When editing Content and removing a Relation between this content and another contenttype, storing the Content will throw an error:

Bolt\Entity\Relation::getFromContent(): Return value must be of type Bolt\Entity\Content, null returned

Details

Question Answer
Relevant Bolt Version master
Install type Composer install
BC Break no
PHP version 8.1
Web server Apache

Reproduction

Bug summary

The problem lies in the $newRelations collection still having the removed relation in its items; when doing the "re-add new relations" bit after the remove, it'll try to look up the related Content items for that relations, which will fail because they've already been nulled. The fix is to explicitly remove the relation from the $newRelations collection.