On 5 May 2006, John Siracusa wrote: > There's no way around copying every field when making a copy! :) That's > just what RDBO's (undocumented) clone() method does. It's not documented > because I'm not sure if it does everything that a clone method should do. > You can be the first to try it and find out! :)
> my $obj = MyClass->new(nr=>1)->load; > > my $obj2 = $obj->clone; # copies all column values into a new object > > $obj2->id(undef); # still need to erase the primary key value > $obj2->price($a_changed_value); # make any other changes... > > # Don't really "need" to do this, but it will save a db connection > $objs->db($obj->db); > > $obj2->save; > > Try it and tell me what you think. Works great but also makes greedy. How about a related method that also deletes the primary key and sets the db. And if the 'set' accessors returned the object, even this would be possible: $obj->clone->some_field('new value')->save; Too greedy? Then perhaps this one?: $obj->clone(some_field => 'new value')->save; But even without any changes clone() helps a lot! Thanks, Michael ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object