[Dbix-class] Shortcut to get to schema from rows?

Jess Robinson castaway at desert-island.me.uk
Tue Apr 7 15:14:23 GMT 2009


On Tue, 7 Apr 2009, Toby Corkindale wrote:

> Hi,
> I find myself doing the following in my table classes often, and wondered if 
> there's a more elegant way?
>
> package MyApp::Schema::Foo;
> __PACKAGE__->table('foo');
> ...
> sub frobnicate {
>   my $self = shift;
>   $self->result_source->schema->txn_do(
>     sub {
>       $self->some_relationship->do_stuff;
>       $self->another_thing->do_stuff;
>       $self->status('frobnicated');
>    }
>  ) ;
>  return $self;
> }

Thats the only way, currently.

>
> So really I just wondered if txn_do() was available at a closer level?
> I mean, there's nothing stopping me making my table classes inherit from a 
> base class which look like the following, but I figured maybe you'd already 
> implemented something like it?
>
> package MyApp::TableBaseClass;
> sub txn {
>  return shift->result_source->schema->txn_do(@_);
> }
>

Nope, go for it..

BTW: I'd CC your email but eclipse fails to parse "DBIx:" sanely and 
thinks its a bug.. tsk ;)

Jess




More information about the DBIx-Class mailing list