-
-
Notifications
You must be signed in to change notification settings - Fork 194
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
Avoid loading already loaded relations and allow loading non studly relation names #773
base: main
Are you sure you want to change the base?
Conversation
Eg In which case |
Also worth noting that with the new normalizer the data class will find the property whether $dataClass = new class () extends Data {
#[DataCollectionOf(FakeNestedModelData::class), MapInputName(SnakeCaseMapper::class)]
public array|Optional $fakeNestedModels;
#[MapInputName(SnakeCaseMapper::class)]
public string $oldAccessor;
}; This is due to But I believe this is not really undesirable behavior |
I was checking the new code and noticed the nested eager load (4.5.1...4.6.0#diff-5a676e204bcb067cd1bf62ef73416609c339f8e16479ab7b38021e9799c2d607R82). Is it possible to remove this line completely? If you have a collection of models it'll create an n+1 relation loading issue when creating a property from a relation. The issue remains even when using I was going to create a PR for it, but maybe we can include it in this one? I believe I also highlighted the issue a while ago (in this repo or another) where a newly introduced nested eager load triggered a ton of queries in our app and we didn't catch it for a long time because it was included in a minor or patch release. The n+1 exception isn't thrown because the relation isn't lazy loaded. |
That doesn't really matter, you're already in charge of this because this only happens with a special attribute and not by default so you already have to be explicit about it (that's why it's in a minor with no breaking change), of course if you have 4 nested relations with 100 of models you'll want to load them yourself, but for 10 models with 1 level or 2 of nesting, it's not worth removing this feature With We could improve it by computing the DataProperty type of each relation and eager load all of them with the attribute, but it might be a big amount of work and it needs to handle/avoid recursive relations like |
load
would load relations even if they were already loaded in the modelBut we might not even need to do that explicitely because
$this->model->{$studlyName}
would also load itAdded a fix for #787 as well