[Dbix-class] Encapsulate multiple steps for insertion

Robert 'phaylon' Sedlacek rs at 474.at
Mon Jan 15 10:19:42 GMT 2007


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?

-- 
# Robert 'phaylon' Sedlacek
# Perl 5/Catalyst Developer in Hamburg, Germany
{ EMail => ' rs at 474.at ', Web => ' http://474.at ' }



More information about the Dbix-class mailing list