On 5/22/07, Matt S Trout <[EMAIL PROTECTED]> 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) = @_;
>    my $dbh = $self->result_source->schema->storage->dbh;
>
>    my $sth = $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 = $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
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to