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

John Goulah jgoulah at gmail.com
Tue May 22 17:16:20 GMT 2007


On 5/22/07, Matt S Trout <dbix-class at trout.me.uk> wrote:
>
> On Mon, May 21, 2007 at 05:19:05PM -0400, John Goulah wrote:
> > I've read the cpan info on DBIx::Class::CDBICompat, but cant seem to get
> an
> > actual working example going.  In particular I want the sth_to_objects
> > method, which I believe is in the ImaDBI component. I'm perhaps
> complicating
> > things further by loading the  ResultSetManager component so that I can
> > execute and return a result set in my object.  I've tried making
> CDBICompat
> > the base class, and also loading as a component.
>
> Please next time ask on the list how to achieve your original aim first,
> if you find yourself loading CDBICOmpat for anything other than its
> original
> purpose you've started off down a rat hole and what you're attempting to
> implement is almost certainly the wrong solution.



OK.  Sorry about that.  My aim is to use the DBIx syntax whenever possible
with a way to use SQL when I get stuck.  Again I know this goes against the
design somewhat, but it would allow me to get things working until I figure
out the "correct" way.


> 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?


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


More information about the Dbix-class mailing list