Skip to content

Regression after PR #55471: Error when accessing nested attributes in manually set relations #55535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tabuna opened this issue Apr 24, 2025 · 5 comments

Comments

@tabuna
Copy link
Contributor

tabuna commented Apr 24, 2025

Laravel Version

12.10.1

PHP Version

8.4

Database Driver & Version

No response

Description

After merging #55471, a regression was introduced in how manually set relations are handled via setRelations(). Behavior that previously returned null now results in a fatal error.

Attempts to address this in #55518 and #55519 do not fully restore the expected behavior.

Steps To Reproduce

$model = new class extends Model {};

$model->setRelations(['many' => ['one', 'two', 'three' => 84]]);

$result = $model->getAttribute('many.three');

✅ Expected behavior:

In versions prior to 12.10.1, this would return null.

❌ Actual behavior:

As of 12.10.1 (and with the mentioned PRs applied), the following error is thrown:

Error: Call to a member function relationLoaded() on null
@rodrigopedra
Copy link
Contributor

rodrigopedra commented Apr 24, 2025

Everything related to these changes were reverted at: dc5b445

Please update to Laravel 12.10.2

@realodix
Copy link

@rodrigopedra

I see the test is removed completely (dc5b445). Is it possible for you to add a regression test like this

$model = new class extends Model {};

$model->setRelations(['many' => ['one', 'two', 'three' => 84]]);

$result = $model->getAttribute('many.three');

@rodrigopedra
Copy link
Contributor

This would be a test to prevent future attempts on this, right?

I know about some test cases added for that reason, like the one which prevents pagination after calling distinct(), but those were all added by maintainers after many failed attempts.

I am not a maintainer, so I am not sure if these kinds of test cases are wanted/accepted, other in those particular cases.

You can give it a try, though.

Anyway, thanks for the suggestion.

@decadence
Copy link
Contributor

Please update to Laravel 12.0.2

12.10.2

@rodrigopedra
Copy link
Contributor

Thanks @decadence !

I updated my comment.

@tabuna tabuna closed this as completed Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants