<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PABLO GODEL &#187; symfony</title>
	<atom:link href="http://pablogodel.com/category/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://pablogodel.com</link>
	<description>Software Development / Sailing / Photography / House Music</description>
	<lastBuildDate>Sun, 08 Nov 2009 03:42:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Duplicating a propel object</title>
		<link>http://pablogodel.com/2009/04/20/duplicating-a-propel-object/</link>
		<comments>http://pablogodel.com/2009/04/20/duplicating-a-propel-object/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 14:42:48 +0000</pubDate>
		<dc:creator>Pablo</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://pablogodel.com/?p=9</guid>
		<description><![CDATA[Today I needed to quickly duplicate some rows in a table that is in a Symfony application. I am using the admin generator so I also have the schema as a Propel series of objects.
I did a quick search on Google and did not find any place on how to effectively duplicate a Propel object [...]]]></description>
			<content:encoded><![CDATA[<p>Today I needed to quickly duplicate some rows in a table that is in a <a href="http://www.symfony-project.org/">Symfony</a> application. I am using the admin generator so I also have the schema as a <a href="http://propel.phpdb.org/trac/">Propel</a> series of objects.</p>
<p>I did a quick search on Google and did not find any place on how to effectively duplicate a Propel object which in turn would duplicate the row in a table.</p>
<p>Basically, what I need is another record with the same values except the primary key which is an autoincremented integer.</p>
<p>Here is the snipped of code that I added to the Propel object.</p>
<pre class="brush: php;">

 public function duplicate()
 {
 // duplicate object
 $ap = clone $this;

 $values = $ap-&gt;toArray( );

 $values2 = array();

 // create array of fields with null so we can force all values to be modified
 foreach( $values as $idx =&gt; $v )
 {
 $values2[ $idx ] = null;
 }

 // force all values to be changed so the doInsert inserts the values.
 $ap-&gt;fromArray( $values2 );
 $ap-&gt;fromArray( $values );

 $ap-&gt;setIsActive(false);
 $ap-&gt;setId(null);
 $ap-&gt;setNew(true);
 $ap-&gt;save();

 return $ap;
 }
</pre>
<p>Is there is another easier way, maybe provided by Propel, which I could not find, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://pablogodel.com/2009/04/20/duplicating-a-propel-object/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
