Skip to content

Loading…

findPk can return unexpected result when instance pool enabled and select() used #758

Open
dimarick opened this Issue · 0 comments

1 participant

@dimarick
//or other query, which adds book 2 to instance pool:
$book = BookQuery::create()->findPk(2); 
...
//many many lines of code
...
// returns string "L. Tolstoy":
$book1 = BookQuery::create()->select(['Author'])->findPk(1); 
// returns instance of Book, but expected simple string:
$book2 = BookQuery::create()->select(['Author'])->findPk(2); 

Works for me:
https://github.com/propelorm/Propel/blob/28ddd83a202214bf2a39e756cb6df91fc450800a/generator/lib/builder/om/QueryBuilder.php#L451

         }
         $pkHash = $this->getPeerBuilder()->getInstancePoolKeySnippet($pks);
         $script .= "
-        if ((null !== (\$obj = {$peerClassname}::getInstanceFromPool({$pkHash}))) && !\$this->formatter) {
+        \$objFormatter = self::FORMAT_OBJECT;
+        if (
+            ((\$this->defaultFormatterClass === \$objFormatter && !\$this->formatter) ||
+                (\$this->formatter instanceof \$objFormatter)) &&
+            (null !== (\$obj = ProjectPeer::getInstanceFromPool((string) \$key)))
+        ) {
             // the object is alredy in the instance pool
             return \$obj;
         }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.