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

Fill $model->_related property on eager load #12

Open
Surt opened this issue Apr 6, 2017 · 1 comment
Open

Fill $model->_related property on eager load #12

Surt opened this issue Apr 6, 2017 · 1 comment

Comments

@Surt
Copy link
Contributor

Surt commented Apr 6, 2017

Hi, I was taking a look at
https://github.com/stibiumz/phalcon.eager-loading/blob/master/src/EagerLoading/EagerLoad.php#L157
the property _related where the relationships are stored is not filled.
This is causing me a problem. When I want to check if a relationship is already loaded, (by any way) if not, then I check caché or fetch db.

On pseudocode:

$instances = Loader::from($instances, ['relationshipAlias']);

foreach($instances as $instance) {
    print_r($instance->getRelationshipAlias());
}

// on the model for $instance I have
public function getRelationshipAlias() {
     if(!isset($this->_related['relationshipAlias']) || $this->_related['relationshipAlias'] === null) {
           // get from cache or fetch from db using getRelated('relationshipAlias');
     }
}

The problem here is that on that case, the eagerloaded relationships are wasted. Of course, if I try to check if the relationship is loaded using the property relationshipAlias, in case that the relationship is not loaded it will make a lazy loading "automatically", runining my chance to insert the caché.

Surt added a commit to Surt/incubator that referenced this issue Apr 6, 2017
When using relationships lazy loading along with magic "getPropertyName" methods the relationships are lazy loaded without having the eager load in consideration. This patch fix it.

References: stibiumz/phalcon.eager-loading#12
@Surt
Copy link
Contributor Author

Surt commented Apr 6, 2017

The problem here is that _relatedis a protected property :(

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