[Dbix-class] using DBIx::Class::CDBICompat

John Goulah jgoulah at gmail.com
Tue May 22 19:42:36 GMT 2007


On 5/22/07, Matt S Trout <dbix-class at trout.me.uk> wrote:
>
> On Tue, May 22, 2007 at 12:16:20PM -0400, John Goulah wrote:
> > >So I have a function like:
> > >>
> > >> sub get_some_data : ResultSet {
> > >>    my ($self) =3D @_;
> > >>    my $dbh =3D $self->result_source->schema->storage->dbh;
> > >>
> > >>    my $sth =3D $dbh->prepare("select * from sometable");
> > >>    $sth->execute();
> > >>
> > >>    ##### this doesn't work, how do I  use this method?
> > >>    return $self->sth_to_objects($sth);
> > >
> > >You don't. That's a method on a resultset object, and the CDBICompat
> stuff
> > >won't show up there - which is a good thing, since sth_to_objects it
> > >pretty
> > >horrible since it's a COMPATIBILITY LAYER feature, not a DBIC feature.
> > >
> > >How about
> > >
> > >    my @results;
> > >    while (my $hr =3D $sth->fetchrow_hashref) {
> > >      push(@results,
> > >        $self->result_class->inflate_result(
> > >          $self->result_source, $hr, {}
> > >        )
> > >      );
> > >    }
> > >    return @results;
> > >
> > >?
> >
> >
> >
> > Yes thats exactly what I was looking for, thank you.  So if I were to
> want
> > this method shared on all my resultset objects, would you suggest
> creating
> > an object that inherits from the ResultSetManager (or somethign similar)
> and
> > putting it in there?
>
> A class that uses base DBIx::Class::ResultSet and then just do
>
> __PACKAGE__->resultset_class('My::ResultSet::Class');
>
> in any table class that needs it. ResultSetManager is just a convenience
> syntax to that, and causes enough problems in more complex cases there's
> serious consideration being given to deprecating it in favour of saner
> syntax.



That works fine, but I would rather scope the package under myDB rather than
MyApp, but when I put the ResultSet dir under myDB directory I get "Cannot
load schema class" errors (under MyApp its fine).  I assume its trying to
load this class as a table class.  Is there any way around this?  If not
where is the recommended place to put these?   It seems best to keep it
close to the DB classes, but I'm not sure Catalyst will let me.


Thanks!
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070522/043=
5f461/attachment.htm


More information about the Dbix-class mailing list