protected function addIsVersioningNecessary(&$script)
 {
     $peerClass = $this->builder->getStubPeerBuilder()->getClassname();
     $script .= "\n/**\n * Checks whether the current state must be recorded as a version\n *\n * @param PropelPDO \$con An optional PropelPDO connection to use.\n *\n * @return  boolean\n */\npublic function isVersioningNecessary(\$con = null)\n{\n    if (\$this->alreadyInSave) {\n        return false;\n    }\n\n    if (\$this->enforceVersion) {\n        return true;\n    }\n\n    if ({$peerClass}::isVersioningEnabled() && (\$this->isNew() || \$this->isModified() || \$this->isDeleted())) {\n        return true;\n    }";
     foreach ($this->behavior->getVersionableFks() as $fk) {
         $fkGetter = $this->builder->getFKPhpNameAffix($fk, $plural = false);
         $script .= "\n    if (null !== (\$object = \$this->get{$fkGetter}(\$con)) && \$object->isVersioningNecessary(\$con)) {\n        return true;\n    }\n";
     }
     foreach ($this->behavior->getVersionableReferrers() as $fk) {
         if ($fk->isLocalPrimaryKey()) {
             $fkGetter = $this->builder->getRefFKPhpNameAffix($fk);
             $script .= "\n    if (\$this->single{$fkGetter}) {\n        // to avoid infinite loops, emulate in save\n        \$this->alreadyInSave = true;\n\n        if (\$this->single{$fkGetter}->isVersioningNecessary(\$con)) {\n            \$this->alreadyInSave = false;\n\n            return true;\n        }\n\n        \$this->alreadyInSave = false;\n    }\n";
         } else {
             $fkGetter = $this->builder->getRefFKPhpNameAffix($fk, $plural = true);
             $script .= "\n    if (\$this->coll{$fkGetter}) {\n        // to avoid infinite loops, emulate in save\n        \$this->alreadyInSave = true;\n\n        foreach (\$this->get{$fkGetter}(null, \$con) as \$relatedObject) {\n            if (\$relatedObject->isVersioningNecessary(\$con)) {\n                \$this->alreadyInSave = false;\n\n                return true;\n            }\n        }\n\n        \$this->alreadyInSave = false;\n    }\n";
         }
     }
     $script .= "\n\n    return false;\n}\n";
 }