[Dbix-class] Encapsulate multiple steps for insertion
Jess Robinson
castaway at desert-island.demon.co.uk
Fri Jan 19 14:52:54 GMT 2007
On Thu, 18 Jan 2007, Pedro Melo wrote:
> 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.
>
So do I now, and it's integrated into DBIx::Class core itself. Try looking
in the bulk_create branch in svn. (still need to write tests for has_many,
but the code should be almost complete)
Jess
More information about the Dbix-class
mailing list