Closed omegasteffy closed 10 years ago
I see. This may be a problem with the with
method not properly loading relations and getting them ready for use. I will have to take a look at this in further detail.
Can you verify that it works properly without using the with
method? I know it's not ideal since it generates many more queries, but I just want to see if we can at least get a working baseline.
(not certain) I believe it works if i leave out the with(), will verify next time i get to the code.
ok some protocode
$matching_ves= $mapper->all('Entity\Vessel_entity');
foreach($matching_ves as $one_ves){
//var_dump($one_ves);
echo 'id:'.$one_ves->id.", vdrs cnt".$one_ves->vdrs->count().'
';
}
id:78, vdrs cnt0
id:79, vdrs cnt0
id:80, vdrs cnt0
id:81, vdrs cnt0
id:82, vdrs cnt0
id:83, vdrs cnt0
id:84, vdrs cnt0
id:85, vdrs cnt0
id:86, vdrs cnt0
id:87, vdrs cnt0
id:88, vdrs cnt0
id:89, vdrs cnt0
leaving out the with('vdrs') id:78, vdrs cnt0 id:79, vdrs cnt0 id:80, vdrs cnt1 id:81, vdrs cnt1 id:82, vdrs cnt1 id:83, vdrs cnt1 id:84, vdrs cnt1 id:85, vdrs cnt1 id:86, vdrs cnt1 id:87, vdrs cnt1 id:88, vdrs cnt0 id:89, vdrs cnt0
So the problem seems to be the eager loading fails. or perhabs rather the count() can not be trusted.
I am currently trying to create a test scenario to reproduce this issue.
Great to hear. Reply if you have difficulties reproducing.
There is definitely an issue with the with
eager-loading method and HasManyThrough relations. I will take a deeper look and get it sorted out.
My setup for HasManyThrough Vessel_entity <-> xTable <-> Vdr_entity
I can get a list of vdrs like this $all_vdrs= $mapper->all('Entity\Vdr_entity')->with('vessels'); relations should be loaded
Now i create a foreach-loop to iterate.Within this a access $one_vdr->vessels foreach ($all_vdrs as $one_vdr){ $cnt= $one_vdr->vessels->count(); //return 0, even if one or more vessels are present $one_ves= $one_vdr->vessels->first();// works ok if there is a relation in the crosstable. It fails otherwise. I have no way of checking (exception handling could be a possibility) }
I have tried $mapper->get(Entity\Vdr_entity,array('id =>1')); in this case i can actually use the count() method