Current Behavior
Initially reported here: https://discuss.flarum.org/d/5791-masquerade-by-friendsofflarum-the-user-profile-builder/230. I found that the issue is in Flarum core.
Using eagerLoadWhere() with a nested relationship can cause an API request to fail with:
Call to undefined relationship [user] on model [Flarum\User\User].
Moving the nested load into a with() callback inside eagerLoadWhere('user', ...) resolves the error.
Steps to Reproduce
See this code: https://github.com/FriendsOfFlarum/masquerade/blob/40c4f6284c56810c6231b189e1e4c6bddd138d60/extend.php#L105-L107
Workaround: https://github.com/FriendsOfFlarum/masquerade/pull/120/changes
Expected Behavior
Loading a nested relationship should not cause an undefined relationship error.
Screenshots
No response
Environment
- Flarum version: v2.0.0-rc.8
Output of php flarum info
No response
Possible Solution
No response
Additional Context
AI-assisted analysis (GPT Astra-6):
The suspected cause is in getWhereEagerLoadsFor() in:
|
$subRelations[$relation] = Str::after($relation, "$included."); |
This keeps the full relationship path as the key and replaces the constraint callback with a string. EloquentBuffer passes the result to with() on the related model's query.
The suggested fix is to use the relative path as the key and preserve the callback, passing it the query and context. This core change has not been tested.
Current Behavior
Initially reported here: https://discuss.flarum.org/d/5791-masquerade-by-friendsofflarum-the-user-profile-builder/230. I found that the issue is in Flarum core.
Using
eagerLoadWhere()with a nested relationship can cause an API request to fail with:Moving the nested load into a
with()callback insideeagerLoadWhere('user', ...)resolves the error.Steps to Reproduce
See this code: https://github.com/FriendsOfFlarum/masquerade/blob/40c4f6284c56810c6231b189e1e4c6bddd138d60/extend.php#L105-L107
Workaround: https://github.com/FriendsOfFlarum/masquerade/pull/120/changes
Expected Behavior
Loading a nested relationship should not cause an undefined relationship error.
Screenshots
No response
Environment
Output of
php flarum infoNo response
Possible Solution
No response
Additional Context
AI-assisted analysis (GPT Astra-6):
The suspected cause is in
getWhereEagerLoadsFor()in:framework/framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php
Line 254 in 4686ef5
This keeps the full relationship path as the key and replaces the constraint callback with a string. EloquentBuffer passes the result to
with()on the related model's query.The suggested fix is to use the relative path as the key and preserve the callback, passing it the query and context. This core change has not been tested.