Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

DBIx::Class "Can't call method 'select' on an undefined value"

by sundialsvc4 (Abbot)
on Jan 21, 2009 at 23:44 UTC ( #737992=perlquestion: print w/replies, xml ) Need Help??
sundialsvc4 has asked for the wisdom of the Perl Monks concerning the following question:

Okay, let me start over on this post... :-)

The code looks like this:

my $schema = My::Schema::Class->connect ("dbi:mysql:dbname=BLAHBLAH;host=localhost", "BLAH", "HEAPBIGSECRET", {AutoCommit => 1}) or croak("cannot connect to main database"); # Strobe the database-connection right now to be sure it's here $schema->storage->ensure_connected(); croak("connection failed to main database") unless $schema->storage->connected;

So far so good... but now, in my test-script...
lives_ok { require My::Schema::Class::TFoodtype} "required OK"; lives_ok { My::Schema::Class->load_classes(qw/TFoodtype/) } "loaded one again"; isa_ok($s->schema->resultset('TFoodtype'), "DBIx::Class::ResultSet");

And this is what fails:
my @records; lives_ok { @records = $s->schema ->resultset('TFoodtype') ->search({foodtype=>'YUM'})->all() } "searched okay";

This is what it says:

Can't call method "select" on an undefined value at (..blah..)/5.8.8/DBIx/Class/ResultSet.pm line 514.

Now, if you study the test-script closely (it uses Test::More and Test::Except ...), you will see that I am trying to systematically check everything I can think of. I know, by this point, that the connection is present. I know that the class is loaded. I know that the resultset('TFoodtype') call is returning a result-set. So it comes down to the final call... and I know that I am doing something abjectly stupid here and I just can't see it!

(Whimper...) My hand is poised, ready to slap my forehead...

Replies are listed 'Best First'.
Re: DBIx::Class "Can't call method 'select' on an undefined value"
by sundialsvc4 (Abbot) on Jan 22, 2009 at 01:07 UTC

    Looking further, the test:

    is($rs->result_source->schema, $s->schema, "belongs to the same schema");

    Fails with the message:

    # Failed test 'belongs to the same schema' # at t/0200_db/0200_dbconnect.t line 52. # got: 'My::Schema::Class' # expected: 'My::Schema::Class=HASH(0x8a163c4)'

    It appears to be saying that one is a string and the other is a hash...

    And indeed, $rs->result_source->storage is undefined.

Re: DBIx::Class "Can't call method 'select' on an undefined value"
by sundialsvc4 (Abbot) on Jan 22, 2009 at 01:57 UTC

    And doing load_classes in the schema base-file “magically” fixes it.

    Not good enough for me... I wanna understand this.

      load_classes() ensures everything is hooked together properly. It's a bit of side-effect magic that mst isn't thrilled with, but at least it's (mostly) all in one place. Go talk in #dbix_class@irc.perl.org if you really want to understand more.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: DBIx::Class "Can't call method 'select' on an undefined value"
by Your Mother (Chancellor) on Jan 22, 2009 at 01:06 UTC

    This is mostly guesswork so take it with a grain of salt but it looks like your test is not where your error is. That select error is related to calling ->cursor. Are you using DBIC cursors in there somewhere...? Your storage is apparently getting undefined/lost somewhere in any case. You could insert a test for that and move it back until you find the trigger.

Re: DBIx::Class "Can't call method 'select' on an undefined value"
by jasonk (Parson) on Jan 22, 2009 at 02:31 UTC

    What is $s? I would suspect that $s->schema is returning something other than the $schema object, like maybe the schema class name?


    www.jasonkohles.com
    We're not surrounded, we're in a target-rich environment!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://737992]
Approved by almut
help
Chatterbox?
[karlgoethebier]: Discipulus: Perhaps i should add some more of these idiots to my sig?
[karlgoethebier]: Discipulus: There are countries were people get imprisoned for things like this...
[1nickt]: Are there enough bytes for all the idiots you would need to include?
[choroba]: I find it more entertaining to have something clever there
[Discipulus]: ys Karl i know; there are also children who die in mines where precious metals for phones are taken
[Discipulus]: 1nickt for sure no! post has 64k limit..
[1nickt]: Until recently I had a sticker on my truck (in NJ) "Keep the immigrants. Deport Trump."
[Discipulus]: i'm just talking about what is appropriate to have here at PM, and I have no a solution but just some thougths
[1nickt]: But I removed it when I travelled to somewhere more, er ... red. Why? Because I thought how stupid I would feel ...
[karlgoethebier]: 1nickt: I fear not. Perhaps enough for Europe...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-06-22 12:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.