Fixed getRelationOrDefault / hydrateDefaultFromRelation attempts to hydrate an auto increment key

DragonByte Tech

Well-known member
Affected version
Assume an already saved entity from this database table record:


With this relation:
            'Address' => [
                'entity' => 'Addon:Address',
                'type' => self::TO_ONE,
                'conditions' => 'address_id',
                'primary' => true

Attempting to call $order->getRelationOrDefault('Address') will produce this server error:
InvalidArgumentException: Column 'address_id' is read only, can only be set with forceSet in src/XF/Mvc/Entity/Entity.php at line 593
[*]XF\Mvc\Entity\Entity->set() in src/XF/Mvc/Entity/Entity.php at line 548
[*]XF\Mvc\Entity\Entity->__set() in src/XF/Mvc/Entity/Manager.php at line 604
[*]XF\Mvc\Entity\Manager->hydrateDefaultFromRelation() in src/XF/Mvc/Entity/Entity.php at line 407
[*]XF\Mvc\Entity\Entity->getRelationOrDefault() in src/addons/path/Admin/Controller/Order.php at line 84
[*]path\Admin\Controller\Order->actionEdit() in src/XF/Mvc/Dispatcher.php at line 321
[*]XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 244
[*]XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 100
[*]XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 50
[*]XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2178
[*]XF\App->run() in src/XF.php at line 390
[*]XF::runApp() in admin.php at line 13

If the primary key is a singular auto-increment value, and it's 0 in the parent record, then it should not be hydrated.
Last edited:
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.1.8).

Change log:
Only hydrate autoIncrement relation fields if there is no value in the parent entity. If the field has a value in the parent, an exception is now thrown.
There may be a delay before changes are rolled out to the XenForo Community.
Top Bottom