Login | Register
My pages Projects Community openCollabNet

Discussions > dev > RE: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save()

propel
Discussion topic

Back to topic list

RE: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save()

Reply

Author Soenke Ruempler <ruempler at topconcepts dot com>
Full name Soenke Ruempler <ruempler at topconcepts dot com>
Date 2006-01-06 05:05:22 PST
Message Hi Hans,

Hans Lellelid <mailto:hans at velum dot net> wrote on Tuesday, October 18, 2005
7:45 PM:

> I've just committed a change to the object builder class /
> template to
> provide some support for self-referential foreign keys -- specifically
> in the copy() and save() methods.
>
> I'd like everyone using SVN versions of Propel to be aware of these
> changes and lte me know if anything undesired happens as a result.

I jut checked out the last svn version and tested the behaviour.

If the referring object is the same as the the object being deep-copied,
we'll get into an endless loop. I wrote a little patch for that, maybe it's
tuneable, but it works here:

Index: PHP5ComplexObjectBuilder.php
====================​====================​====================​=======
--- PHP5ComplexObjectBuilder.php (revision 323)
+++ PHP5ComplexObjectBuilder.php (working copy)
@@ -1232,6 +1232,9 @@
        //if ( $fk->getTable()-​>getName() != $table->getName() ) {
         $script .= "
     foreach(\$this-​>get".$this->get​RefFKPhpNameAffix($​fk, true)."() as
\$relObj) {
+ if (get_class(\$this) === get_class(\$relObj) &&
\$this->getPrimaryKey() === \$relObj->getPrimaryKey()) {
+ continue; // we don't want to copy ourself recursivly to avoid an
endless loop
+ }
 
\$copyObj->add"​.$this->getRefFK​PhpNameAffix($fk)."​(\$relObj->copy​(\$deepCopy
));
     }
 ";

--

Sönke Ruempler

« Previous message in topic | 1 of 12 | Next message in topic »

Messages

Show all messages in topic

RE: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() Soenke Ruempler <ruempler at topconcepts dot com> Soenke Ruempler <ruempler at topconcepts dot com> 2006-01-06 05:05:22 PST
     Re: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() hlellelid Hans Lellelid 2006-01-06 05:16:00 PST
         RE: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() Soenke Ruempler <ruempler at topconcepts dot com> Soenke Ruempler <ruempler at topconcepts dot com> 2006-01-06 05:44:14 PST
             Re: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() hlellelid Hans Lellelid 2006-01-06 06:29:34 PST
                 RE: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() Soenke Ruempler <ruempler at topconcepts dot com> Soenke Ruempler <ruempler at topconcepts dot com> 2006-01-06 07:10:30 PST
                     Re: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() hlellelid Hans Lellelid 2006-01-06 07:42:32 PST
                         RE: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() Soenke Ruempler <ruempler at topconcepts dot com> Soenke Ruempler <ruempler at topconcepts dot com> 2006-01-06 07:51:01 PST
                             Re: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() hlellelid Hans Lellelid 2006-01-06 07:58:00 PST
                                 RE: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() Soenke Ruempler <ruempler at topconcepts dot com> Soenke Ruempler <ruempler at topconcepts dot com> 2006-01-24 02:22:22 PST
                 Re: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() Ants Aasma <ants dot aasma at mig dot ee> Ants Aasma <ants dot aasma at mig dot ee> 2006-01-06 07:26:11 PST
                     Re: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() hlellelid Hans Lellelid 2006-01-06 07:39:11 PST
                         Re: [propel-dev] BEHAVIOR CHANGE: self-referential foreign keys in copy() and save() Ants Aasma <ants dot aasma at mig dot ee> Ants Aasma <ants dot aasma at mig dot ee> 2006-01-06 08:08:28 PST
Messages per page: