On 5/5/06 6:25 AM, Michael Lackhoff wrote: > I would like to copy objects from a default record/object. I tried it > with something like: > > use MyClass; > use Clone qw(clone); > > my $obj = MyClass->new(nr=>1)->load; > my $obj2 = clone($obj); > $obj2->id(undef); > $obj2->price($a_changed_value); > $obj2->save; > > but got an error message: > Can't call disconnect method on handle DBI::db=HASH(0x24347d8) after > take_imp_data() at C:/Perl/site/lib/Rose/DB.pm line 623.
That technique (cloning the entire object) clones not just the object values, but also all the internal (private) state information like "is this object in the database" and "does the db object belong to this object only, or is it shared" and so on. > Performance is also an issue because I want to copy whole sets of > related records at a time and I fear that a home grown solution I > could come up with myself (copy every record field for field) would > be quite slow. 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. -John ------------------------------------------------------- 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