jeremyharris / cakephp-lazyload

A lazy loader for CakePHP entities.
MIT License
61 stars 10 forks source link

[bug] Infinite loop check for nullable associations #11

Closed robertpustulka closed 7 years ago

robertpustulka commented 7 years ago

Lazy load seems to be stuck in a loop while loading nullable belongsTo associates. I think that lazy loader should check if a property has been already set to null.

For example:

protected function _lazyLoad($property)
{
    if (array_key_exists($property, $this->_properties)) {
        return $this->_properties[$property];
    }
    ...
}

This might fix #9

jeremyharris commented 7 years ago

I think you're right that this would fix #9. I would have thought this would be handled by the parent's has and get methods, which check the _properties here. At any rate, I'll look into them. Maybe bailing early in the _lazyLoad method would be good (although I'm not totally keen on re-implementing what get does).

jeremyharris commented 7 years ago

Can you check that your null association was fixed by https://github.com/jeremyharris/cakephp-lazyload/commit/ac052a8ba29283d7c6f33ac8a3b4a01db8276f13? I imagine it would be, because null is null after all. If it tries to lazy load even once, it keeps that state so it doesn't try again.

robertpustulka commented 7 years ago

@jeremyharris I've commented the commit

jeremyharris commented 7 years ago

Closed by https://github.com/jeremyharris/cakephp-lazyload/commit/f399a524cef29d168a7ff07d578a8972d606a609

robertpustulka commented 7 years ago

Thanks