[Dbix-class] Clone DBIx::Class::Row object to new connection

Gerhard Heift ml-dbix-class-20090107-b968 at gheift.de
Tue Jun 1 14:28:19 GMT 2010


On Tue, Jun 01, 2010 at 10:24:59AM +0200, Gerhard Heift wrote:
> Hello
> 
> I have a $row object and want to get a clone of it, which is bound to a new
> database connection:

I found a solution for me:

sub clone_db {
        my $self = shift;

        my $schema = $self->result_source->schema->clone;
        my @connect_info = @{$schema->storage->connect_info};

        $schema = ref $schema;
        $schema = $schema->connect(@connect_info);

        my $clone = $schema->resultset($self->result_source->source_name)->new({$self->get_columns});

        $clone->{'_dirty_columns'} = {
                %{$self->{'_dirty_columns'}}
        } if exists $self->{'_dirty_columns'};

        $clone->{'_orig_ident'} = {
                %{$self->{'_orgi_ident'}}
        } if exists $self->{'_orig_ident'};

        $clone->in_storage($self->in_storage);

        return $clone;
}

Anything I missed in this solution?

Regards,
  Gerhard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20100601/7a8a037f/attachment.pgp


More information about the DBIx-Class mailing list