[Dbix-class] Encapsulate multiple steps for insertion
Pedro Melo
melo at simplicidade.org
Thu Jan 18 15:30:55 GMT 2007
Hi,
On Jan 17, 2007, at 9:17 AM, Jess Robinson wrote:
> Hmm, seems I missed this conversation. I'm in the process of adding
> this to a DBIx::Class branch (bulk_create).
>
> The idea will essentially be that you call create once with enough
> info to create all the needed related objects, and it creates them
> in a transaction (all or nothing).
>
> Syntax is currently fairly simple:
>
> $item->create({Name => 'fred',
> Parent => { 'Name' => 'parentoffred'},
> Tags => [ { 'Tag' => 'foo'}, { 'Tag' => 'bar' }],
> });
>
> .. etc, where each hashref can be either a hashref of the related
> tables cols/vals, or an actual object of that table. Use a single
> hashref for a one-to-one rel, and an arrayref for one-many rels.
> The keys there are the relnames or the normal column names,
> depending on the rel types.
I have working code for this if you want. I'm adding many-to-many
support now, because I need it. It will create the link table entry
but will assume the other side already exists in the database.
Best regards,
--
Pedro Melo
Blog: http://www.simplicidade.org/notes/
Jabber ID: melo at simplicidade.org
Use Jabber!
More information about the Dbix-class
mailing list