[Dbix-class] DBIx::Class::ResultSet::RecursiveUpdate - announcement and RFC

Zbigniew Lukasiak zzbbyy at gmail.com
Tue Sep 23 12:35:03 BST 2008


When refactoring code for InstantCRUD I decided it would be useful you
could ->update_or_create recursively (just like you can do now with
the ->create method) so that you could take a hash with the changes
you need in the database and update_or_create all the involved rows.
So DBIx::Class::ResultSet::RecursiveUpdate is born - it is a base
ResultSet class and provides just one additional method
->recursive_update.  So that for example you could edit a person's
data together with her addresses on one form and then update the
database with one call to the ORM.

Unlike the original update_or_create - recursive_update works for
tables with auto_increment primary keys, with the provision that you
need to feed it the 'undef' for the auto_increment PK if you want it
to create a new row (it is then deleted it so a CREATE statement is
issued to the database).

Unfortunately it relies on some not yet released bug fixes - so you
need the svn DBIC version for it to work correctly in some cases.
Until the new version of DBIC is released it is only available from
the svn repository at:
http://dev.catalyst.perl.org/repos/bast/DBIx-Class-ResultSet-RecursiveUpdate/1.000/trunk

All comments are welcome.

-- 
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
http://perlalchemy.blogspot.com/

PS Synopsis:

   __PACKAGE__->load_namespaces( default_resultset_class =>
'+DBIx::Class::ResultSet::RecursiveUpdate' );

in the Schema file (see t/lib/DBSchema.pm).  Or appriopriate 'use
base' in the ResultSet classes.

Then:

    my $user = $user_rs->recursive_update( {
        id => 1,
        owned_dvds => [
        {
          id => undef,
          title => 'One Flew Over the Cuckoo's Nest'
        }
        ]
      }
    );



More information about the DBIx-Class mailing list