in reply to DBIx::Class prefetch problem

The tables look like this:

That doesn't look like a schema :)

Replies are listed 'Best First'.
Re^2: DBIx::Class prefetch problem
by l8gravely (Initiate) on Jan 15, 2015 at 03:47 UTC
    You're right, my question probably wasn't formatted properly. But with a bit of work, I think I've semi-managed to find a work around that I think will work. My new test script does the following, which is basically to run a single query to get the Names and Account tables joined together, then it runs a query for each boxfolder_id found in each Account_id for each Name_id, which is crappily inefficient, but which does the trick in my test script. Now to figure out why it's not working in my Dancer web app the way I expect. My new code is:
    #!/usr/bin/perl -w use DBIx::Class; use lib '../lib'; use Carey::Schema; use Data::Dumper; die "Usage: $0 name\n\n" if $#ARGV < 0; my $name = shift @ARGV; my $schema = Carey::Schema->connect('DBI:mysql:database=careymss;host= +localhost;port=3306', 'kiddb','', { PrintError => 1, RaiseError => 1} +); my $rs = $schema->resultset('Name')->search({ full_name => { regexp => '[[:<:]]'.$n +ame.'[[:>:]]' } }, { rows => 10, prefetch => 'account', order_by => { -asc => 'fu +ll_name' }, }); $schema->storage->debug(1); my @r = $rs->all; foreach my $r (@r) { print "Full Name: ", $r->full_name, " (", $r->name_id, ")\n"; foreach my $a ($r->account()) { print " account_id=", $a->account_id(); print " boxfolder_id=",$a->boxfolder_id()," "; my $t = $a->url(); $t =~ m/value2=(\w+)\&/; print " URL: $1"; my $b = $a->boxfolder(); $vol = $b->{volume}; $folder = $b->{folder}; $range = $b->{range}; print " V=$vol " if defined $vol; print " F=$folder " if defined $folder; print " R=$range " if defined $range; print "\n"; } }
    And I'd appreciate any comnments. Thanks, John

      ..And I'd appreciate any comnments. Thanks, John

      Ok, the bar is low enough :) so here is any comments

      You've posted a description of your tables, which looks very much like an actual schema, but it isn't an actual schema, so anyone actually trying to run that code to help, needs to recreate the schema ... manual labor you've already done that nobody needs to repeat

      or already have tons of experience with DBIx and can just figure out the issue you're having just by looking (not me, i'd have to sqlt the schema to sqlite and go from there)

      Chances are you can find some such person at the irc channel, link https://chat.mibbit.com/#dbix-class@irc.perl.org

        Thanks for the comments, but I thought I provided enough info to properly show the tables and schema I've been trying to define. I'm missing something here, because I just for the life of me cannot make it work where I have: name -> has_many -> account -> has_one boxfolder relationship work. I provided example SQL which does what I want, but I can't get DBIx::Class to do the same thing for some reason. Do I need to provide a complete standalong SQLite example code to show this?