Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix for one-to-one related object have unnecessary queries during hydration #483

Merged
merged 3 commits into from Nov 21, 2012
@@ -3250,13 +3250,14 @@ protected function addFKAccessor(&$script, ForeignKey $fk)
* Get the associated $className object
*
* @param PropelPDO \$con Optional Connection object.
+ * @param \$doQuery Executes a query to get the object if required
* @return $className The associated $className object.
* @throws PropelException
*/
- public function get".$this->getFKPhpNameAffix($fk, $plural = false)."(PropelPDO \$con = null)
+ public function get".$this->getFKPhpNameAffix($fk, $plural = false)."(PropelPDO \$con = null, \$doQuery = true)
{";
$script .= "
- if (\$this->$varName === null && ($conditional)) {";
+ if (\$this->$varName === null && ($conditional) && \$doQuery) {";
if ($useRetrieveByPk) {
$script .= "
\$this->$varName = ".$fkQueryBuilder->getClassname()."::create()->findPk($localColumns, \$con);";
@@ -3952,7 +3953,7 @@ public function set".$this->getRefFKPhpNameAffix($refFK, $plural = false)."($cla
\$this->$varName = \$v;
// Make sure that that the passed-in $className isn't already associated with this object
- if (\$v !== null && \$v->get".$this->getFKPhpNameAffix($refFK, $plural = false)."() === null) {
+ if (\$v !== null && \$v->get".$this->getFKPhpNameAffix($refFK, $plural = false)."(null, false) === null) {
\$v->set".$this->getFKPhpNameAffix($refFK, $plural = false)."(\$this);
}