Skip to content
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

Eager-loaded relations are not cached when null #451

Open
romosan opened this issue Apr 8, 2023 · 0 comments
Open

Eager-loaded relations are not cached when null #451

romosan opened this issue Apr 8, 2023 · 0 comments

Comments

@romosan
Copy link

romosan commented Apr 8, 2023

I hope this is a bug and not a feature, because the latest version of the ORM doesn't cache the result of eager-loading has_many relations (and probably many_many as well) when there are no related records found. This happens at least since the commit 776c245 (speedup of the hydration process) and it causes the relation to be lazy-loaded redundantly when it is accessed for the second time. In 1.8.2, an empty array was set from the first load and it prevented the second one from happening.

In the current \Orm\Query::process_row function, this code seems to me to be the problem:

			// skip the rest if we don't have a pk (= no result)
			if (is_null($pk))
			{
				continue;
			}

Perhaps before this continue, an empty array should be added to $pointers if ($model['singular'] === false).

Edit: A null value doesn't seem to be set in the case of singular relations which haven't been found either.

@romosan romosan changed the title Eager-loaded has_many relations are not cached when null Eager-loaded relations are not cached when null Apr 20, 2023
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

1 participant