[Dbix-class] Encapsulate multiple steps for insertion
Matt S Trout
dbix-class at trout.me.uk
Mon Jan 22 13:22:09 GMT 2007
On 18 Jan 2007, at 15:30, 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.
Please have a look at castaway's bulk_create branch and see what
additional features can be merged in from your code.
And next time, please get a commit bit and a branch off me before you
start hacking so you don't end up duplicating somebody else's work -
if you're looking to hack on DBIC I can always find you plenty of
things that need doing that somebody else isn't already writing :D
--
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for
details.
+ Help us build a better perl ORM: http://dbix-
class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list