Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by sundialsvc4 (Monsignor)
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...

Comment on DBIx::Class "Can't call method 'select' on an undefined value"
Select or Download Code
Re: DBIx::Class "Can't call method 'select' on an undefined value"
by Your Mother (Canon) 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 sundialsvc4 (Monsignor) 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 (Monsignor) 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 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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-08-20 09:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (109 votes), past polls