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

Avoid lazy load if the association is empty #27

Merged
merged 4 commits into from
Jul 14, 2021
Merged

Avoid lazy load if the association is empty #27

merged 4 commits into from
Jul 14, 2021

Conversation

fabiofdsantos
Copy link
Contributor

Fixes #26

@@ -128,7 +128,7 @@ protected function _lazyLoad($property)
->associations()
->getByProperty($property);

if ($association === null) {
if ($association === null || $this->get($association->getBindingKey()) === null) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this fail associations other than belongsTo? They don't have a key on the table.

Copy link
Contributor Author

@fabiofdsantos fabiofdsantos Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I try $article = $this->Articles->get(1), I'm able to get comments via $article->comments.

Can you write a specific test case scenario? Thanks

tests/TestCase/ORM/LazyLoadEntityTraitTest.php Outdated Show resolved Hide resolved
@jeremyharris jeremyharris merged commit 1c0cd9e into jeremyharris:master Jul 14, 2021
@jeremyharris
Copy link
Owner

jeremyharris commented Jul 14, 2021

🚀 Released: https://github.com/jeremyharris/cakephp-lazyload/releases/tag/4.0.2

Thanks for the work!

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

Successfully merging this pull request may close these issues.

Useless queries when primary key is unset
2 participants