phalcon.eager-loading
phalcon.eager-loading copied to clipboard
Fill $model->_related property on eager load
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é.
The problem here is that _related
is a protected property :(