vlucas / Spot

[DEPRECATED - use v2] Simple DataMapper ORM for PHP 5.3+
75 stars 14 forks source link

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

Closed omegasteffy closed 10 years ago

omegasteffy commented 10 years ago

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 commented 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.

vlucas commented 10 years ago

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 commented 10 years ago

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

omegasteffy commented 10 years ago

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 commented 10 years ago

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

omegasteffy commented 10 years ago

Great to hear. Reply if you have difficulties reproducing.

vlucas commented 10 years ago

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 commented 10 years ago

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.