[Dbix-class] Encapsulate multiple steps for insertion

Richard Jolly Richard.Jolly at bbc.co.uk
Mon Jan 15 13:41:22 GMT 2007


Robert 'phaylon' Sedlacek wrote:
> Richard Jolly wrote:
> 
>> Like the OP, whe have business entities that span mulitple tables and
>> need to be created within a transaction. That's simple enough, but
>> the clarity of the code suffers: 
>> 
>>   # good - creates a complete record
>>   $schema->resultset('Foo')->create_bar($data)
>> 
>>   # bad - invalid, partially created business object
>>   #schema->resultset('Foo')->create($data)
>> 
>> We can't just override create, so that wasn't an option - it needs to
>> be called as-is within the create_bar transaction, along with a bunch
>> of other stuff. Get a few cases like that and it's a lot for
>> developers to remember.
> 
> Maybe I'm missing something here, because I just got into the
> office and  am still having my first cup of coffee, but: Why
> not? Or rather, why not override 'insert' to create a
> corresponding entry in the related table?

This code was written months ago now and I can't remember (I'm on my
third cup, but it's not working). I'm pretty sure we tried that, but
looking at the code now I can't see why it wouldn't work. If I get time
I'll play with it later and post an update.

Richard 

http://www.bbc.co.uk/
This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
Please note that the BBC monitors e-mails sent or received.
Further communication will signify your consent to this.
					



More information about the Dbix-class mailing list