[Dbix-class] more schema questions

Matt S Trout dbix-class at trout.me.uk
Fri Jan 6 19:18:05 CET 2006


On Fri, Jan 06, 2006 at 09:19:07AM -0800, Alan Humphrey wrote:
> I'm trying to take baby steps in getting this working, so I've removed
> Catalyst from the equation for the time being.  Today's effort is simply
> getting a single table read.  Following the docs from DBIx::Class::Schema
> I've got the following.
> 
> Schema:
> package BirdWeb::Admin::Model::BirdWebSchema;
> 
> use strict;
> use base qw/DBIx::Class::Schema/;
> __PACKAGE__->load_classes( qw/Birds/ );
> 1;
> 
> Birds:
> package BirdWeb::Admin::Model::BirdWebSchema::Birds;
> 
> use strict;
> use base qw/DBIx::Class/;
> 
> __PACKAGE__->load_components( qw/Core/ );
> 
> __PACKAGE__->table('birds');
> __PACKAGE__->add_columns( qw[id genus_id species_name_id image_id
> north_america_map_id
> 							 washington_map_id
> default_sound_id 
> 	
> default_bird_common_name_id generic_bird_common_name_id
> 							 taxonomic_order
> identification voice habitat behavior
> 							 diet nesting
> migration where_found conservation_status
> 							 notes] );
> __PACKAGE__->set_primary_key( qw[id] );
> 
> 1;
> 
> Database:
> package BirdWeb::Admin::Model::DBIC;
> 
> use strict;
> use BirdWeb::Admin::Model::BirdWebSchema;
> 
> my @conn_info = (
>     'dbi:mysql:BirdWeb',
>     'user',
>     'pass',
>     { RaiseError => 1, PrintError => 0, ShowErrorStatement => 1, TraceLevel
> => 0 }
> );
> 

Remove these two lines -

> __PACKAGE__->compose_connection( __PACKAGE__, @conn_info );
> __PACKAGE__->load_classes;

Replace with

BirdWeb::Admin::Model::BirdWebSchema->compose_connection( __PACKAGE__, @conn_info );

Catalyst::Model::DBIC::Plain puts the schema and the model in the same
namespace because gabb felt that having the database schema not under
MyApp::Model was stylistically wrong. Please don't use it as a guide,
use the DBIx::Class::Schema docs instead.

> 
> 1;
> 
> Test script:
> use Data::Dumper;
> 
> my $obj = BirdWeb::Admin::Model::DBIC::Birds->find(234);

better

my $obj = BirdWeb::Admin::Model::DBIC->class('Birds')->find(234);
 
> print Dumper($obj);
> 
> 
> Result:
> Can't locate object method "find" via package
> "BirdWeb::Admin::Model::DBIC::Birds"
> 
> If I 'use' BirdWeb::Admin::Model::DBIC::Birds then there's a compile time
> error complaining the module can't be found.
> 
> What am I missing?
> 
> Thanks!
> 
> - Alan
> 
> 
> _______________________________________________
> 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/

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list