Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Class::DBIx is driving me to drink!

by blue_cowdawg (Monsignor)
on Jan 29, 2013 at 20:40 UTC ( [id://1015929]=perlquestion: print w/replies, xml ) Need Help??

blue_cowdawg has asked for the wisdom of the Perl Monks concerning the following question:

OK.. so I have this Class::DBIx schema that I've assembled using dbicdump and one of the tables I dumped is called "planet" in the database itself.

If I look in the result set directory I find all the tables represented there including planet.

use MooseX::MarkAsMethods autoclean => 1; extends 'DBIx::Class::Core'; __PACKAGE__->load_components("Schema::Versioned"); __PACKAGE__->table("planet"); __PACKAGE__->add_columns( "planet_id", { data_type => "integer", extra => { unsigned => 1 }, is_auto_increment => 1, is_nullable => 0, }, "starport", { data_type => "integer", default_value => 1, is_nullable => 0 }, "diameter", { data_type => "integer", default_value => 0, is_nullable => 0 }, "atmosphere", { data_type => "integer", default_value => 0, is_nullable => 0 }, "population", { data_type => "integer", default_value => 0, is_nullable => 0 }, "government", { data_type => "integer", default_value => 0, is_nullable => 0 }, "lawlevel", { data_type => "integer", default_value => 0, is_nullable => 0 }, "starorbit", { data_type => "integer", extra => { unsigned => 1 }, is_foreign_key => 1, is_nullable => 0, }, ); __PACKAGE__->belongs_to( "starorbit", "RPG::Traveller::DBIx::Starmap::Schema::Result::Starorbit", { starorbit_id => "starorbit" }, { is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRIC +T" }, ); __PACKAGE__->set_primary_key("planet_id"); __PACKAGE__->meta->make_immutable;
(I excised out the embedded POD)

So.. why when I run a test against this (or write code against it it can't be found in the schema?

For those curious here's my test (very simple):

use Test::More tests => 1; { use RPG::Traveller::DBIx::Schema; my $db = RPG::Traveller::DBIx::Schema->connect( 'dbi:mysql:hostname=localhost:database=starmapper', 'starmapper', 'secretsquirrel' ); # not the real creds above... $db->resultset('Planet'); }

Test bombs with:

t/10-planet.t ............. Can't find source for Planet at /usr/lib/p +erl5/site_perl/5.14/DBIx/Class/Schema.pm line 1101. DBIx::Class::Schema::throw_exception('RPG::Traveller::DBIx::Sc +hema=HASH(0x2006c030)', 'Can\'t find source for Planet') called at /u +sr/lib/perl5/site_perl/5.14/DBIx/Class/Schema.pm line 599 DBIx::Class::Schema::source('RPG::Traveller::DBIx::Schema=HASH +(0x2006c030)', 'Planet') called at /usr/lib/perl5/site_perl/5.14/DBIx +/Class/Schema.pm line 550 DBIx::Class::Schema::resultset('RPG::Traveller::DBIx::Schema=H +ASH(0x2006c030)', 'Planet') called at t/10-planet.t line 8


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re: Class::DBIx is driving me to drink!
by Your Mother (Archbishop) on Jan 29, 2013 at 20:59 UTC
    s/Class::DBIx/DBIx::Class/; # your link

    Where is the package declaration for your Planet result source (table) class? Copy+paste omission or really missing? Should probably be package RPG::Traveller::DBIx::Schema::Result::Planet;

      Ok.. time for me to shut down emacs and go home... I fat fingered the path... RPG::Traveller::DBIx::Starmap::Schema instead of RPG::Traveller::DBIx::Schema... DOH!

      There may be another post on this later though... I'm seeing other wonkyness but that's for tomorrow...


      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Class::DBIx is driving me to drink!
by stonecolddevin (Parson) on Jan 29, 2013 at 21:50 UTC

    Check out Test::DBIx::Class, maybe it'll help you aggregate some of your test logic and abstract a few things so you can cut down on your typing.

    Three thousand years of beautiful tradition, from Moses to Sandy Koufax, you're god damn right I'm living in the fucking past

          Check out Test::DBIx::Class

      That's some neat stuff.

      One thing I'm not sure about though:

      use Test::More; use strict; use warnings; use Test::DBIx::Class qw(:resultsets); ## Your testing code below ## ## Your testing code above ## done_testing;
      How in the world does Test::DBIx::Class know to look for the result sets? PFM?


      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Class::DBIx is driving me to drink!
by choroba (Cardinal) on Jan 29, 2013 at 20:47 UTC
    Never used DBIx::Class. But is the case mismatch ('planet' vs. 'Planet') ok?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      When dbicdump does its thing it upcases the first character of the module name it creates in the result sets. So (at least in theory) you should be able to

      # Create a new row in the table planet my $new_planet=$db->resultset('Star')->new({...blah...}); $planet->insert();
      among other things. Just to be sure I am able to select other result set objects
      my $new_mode = $db->resultset("Starmode")->new({starmode=> $mo +de}); $new_mode->insert; ---- my $new_size = $db->resultset("Starsize")->new({starsize=> $size}) +; $new_size->insert(); --- my $new_sgt = $db->resultset("Stargrouptype")->new({type=>$sgt}); $new_sgt->insert(); --- my $new_type = $db->resultset("Startype")->new({startype=>$type}); $new_type->insert();
      for instance.


      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1015929]
Front-paged by Lotus1
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-03-19 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found