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

HasManyThrough, fails to detect missing relation, when aquired by mapper->all() #68

Closed
omegasteffy opened this Issue Jan 24, 2014 · 8 comments

Comments

Projects
None yet
2 participants
@omegasteffy

omegasteffy commented Jan 24, 2014

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

@vlucas

This comment has been minimized.

Owner

vlucas commented Jan 24, 2014

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.

@vlucas

This comment has been minimized.

Owner

vlucas commented Jan 24, 2014

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.

@omegasteffy

This comment has been minimized.

omegasteffy commented Jan 24, 2014

(not certain)
I believe it works if i leave out the with(), will verify next time i get to the code.

@omegasteffy

This comment has been minimized.

omegasteffy commented Jan 24, 2014

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.

@vlucas

This comment has been minimized.

Owner

vlucas commented Jan 28, 2014

I am currently trying to create a test scenario to reproduce this issue.

@omegasteffy

This comment has been minimized.

omegasteffy commented Jan 28, 2014

Great to hear. Reply if you have difficulties reproducing.

@vlucas

This comment has been minimized.

Owner

vlucas commented Jan 28, 2014

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.

@vlucas

This comment has been minimized.

Owner

vlucas commented Aug 14, 2014

This has been solved with the release of Spot v2. Due to poor architecture that will lead to invariable replication of code, this will not be solved in this version of Spot.

@vlucas vlucas closed this Aug 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment