[Dbix-class] Re: Creating rows

Zbigniew Lukasiak zzbbyy at gmail.com
Sat Jan 5 16:29:52 GMT 2008


Hate replying to myself - but

On Jan 5, 2008 5:23 PM, Zbigniew Lukasiak <zzbbyy at gmail.com> wrote:
> Happy New Year!
>
> I've recently learned that in DBIC you can do something like:
>
>  $user_rs->create( { name => 'new nick', addresses => [
>             { address => 'new address' },
>             { address => 'new address 2' },
>             ]
>       }
>  );
>
> and have the related rows created.
>
> When refactoring the FormFu::Model::DBIC code I've reached a point
> where it would be useful to do:
> $user->update_with_relations( { name => 'new nick', addresses => [
>             { id => 2, address => 'new home' },
>             { id => 3, address => 'new office'},
>             { id => undef, address => 'new address'},
>             ]
>         }
>     );
> and have the (already existing) related rows updated.  Unfortunately
> when I do that DBIC tries to insert them and fails because their ids
> are already taken (the last one, with id => undef, works as expected -
> a new row is inserted).

I wanted to write it fails when I do "$user->update( {.... " - i.e.
when I use the standard 'update' method not the hypothetical
update_with_relations.

Zbigniew



More information about the DBIx-Class mailing list