On 6/25/07, Iļja Ketris <[EMAIL PROTECTED]> wrote:
> I am trying to achieve a simple task of updating many columns in a row from
> a hash. %hash = (field1=>'foo', field2=>'bar' ...)
> While I can pass a hash to the "new" method
>
> $product = Product->new (%hash);
>
> I don't see a simple way to update a previously loaded row:
>
>  $product = Product->new (id=>$id);
> $product->load;
>
> # $product <----- %hash ?

All new() does is pass its args to init(), which you can call directly:

http://search.cpan.org/dist/Rose-Object/lib/Rose/Object.pm#init

$product = Product->new(id => $id)->load;
$product->init(%hash);

Of course, that depends on %hash being a bunch of mutator-method/value
pairs.  That is usually the same thing as column/value pairs, but not
always.  To be safe, you may want to use the
init_with_column_value_pairs() helper method:

http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Helpers.pm#init_with_column_value_pairs

> There is no way to bypass column methods to set values directly.

All the methods described above go through the column mutator methods.
 This is considered a feature :)

-John
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to