[Dbix-class] Use of ->resultset mandatory?

Mike Friedman friedo at friedo.com
Mon Oct 30 22:11:20 GMT 2006


On 10/30/06, Steven Mackenzie <dbix at aptile.co.uk> wrote:
>
>
> In my quest to avoid typing resultset(''), is there a reason why I can't
> have source_name create accessors in the $shema object, eg,
>   $schema->MyBest->search;
>
>
In my experimenting, I've been doing stuff like this in my CGI::Application
base class:

sub cgiapp_prerun {
    my $self =3D shift;
    my $schema =3D MyDB::Main->connect( ... );

    $self->param( schema =3D> $schema );
}

sub schema {
    my $self =3D shift;
    return $self->param( 'schema' );
}

sub user {
    my $self =3D shift;
    return $self->schema->resultset('User')
}


Then, in a subclass, I can say:

sub foo_runmode {
    my $self =3D shift;
    my $user =3D $self->user->search( id =3D> "foo" );
}


I can even auto-generate the per-table accessors from the schema.

Of course, I have no idea if any of this is a good idea. Use at your own
peril. :)


Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jules.scsys.co.uk/pipermail/dbix-class/attachments/20061030/77e=
23408/attachment.htm


More information about the DBIx-Class mailing list