[Dbix-class] newbie user problem

Hermida, Leandro Leandro.Hermida at fmi.ch
Thu Nov 23 15:44:13 GMT 2006


Hello everyone,
 
I cannot seem to get a simple DBIx::Class setup to work.  I was
wondering if anyone
sees what I am doing wrong...
 
---
In "lib/MySchema.pm":
 
package MySchema;
use base qw(DBIx::Class::Schema);
__PACKAGE__->load_classes();

1;
 
---
In "lib/MySchema/Author.pm":
 
package MySchema::Author;
use base qw(DBIx::Class);
 
__PACKAGE__->load_components(qw(PK::Auto Core));
__PACKAGE__->table('authors');
__PACKAGE__->add_columns(qw(id first_name last_name));
__PACKAGE__->set_primary_key(qw(id));

__PACKAGE__->has_many(book_authors => 'MySchema::BookAuthor',
'author_id');
__PACKAGE__->many_to_many(books => 'book_authors', 'book');

1;
 
---
In "lib/MySchema/Book.pm":
 
package MySchema::Book;
 
use base qw(DBIx::Class);
 
__PACKAGE__->load_components(qw(PK::Auto Core));
__PACKAGE__->table('books');
__PACKAGE__->add_columns(qw(id title rating));
__PACKAGE__->set_primary_key(qw(id));

__PACKAGE__->has_many(book_authors => 'MySchema::BookAuthor',
'book_id');
__PACKAGE__->many_to_many(authors => 'book_authors', 'author');

1;
 
---
In "lib/MySchema/BookAuthor.pm":
 
package MySchema::BookAuthor;
use base qw(DBIx::Class);
 
__PACKAGE__->load_components(qw(PK::Auto Core));
__PACKAGE__->table('book_authors');
__PACKAGE__->add_columns(qw(book_id author_id));
__PACKAGE__->set_primary_key(qw(book_id author_id));
 
__PACKAGE__->belongs_to(book => 'MySchema::Book', 'book_id');
__PACKAGE__->belongs_to(author => 'MySchema::Author', 'author_id');

1;
 
---
In "test.pl":
 
#!/usr/bin/perl
 
use strict;
use warnings;
use lib 'lib';
use MySchema;
 
my $schema =
MySchema->connect('DBI:mysql:database=MyApp;host=localhost;port=3306',
'testuser', 'testpass', { PrintError => 0, RaiseError => 1, AutoCommit
=> 0 });
 
my @books = $schema->resultset->('Book')->all;

---
I get these errors which I cannot understand:
 
[hermida at dla2 test]$ ./test.pl 
Use of uninitialized value in exists at
/usr/lib/perl5/site_perl/5.8.5/DBIx/Class/Schema.pm line 146.
Use of uninitialized value in hash element at
/usr/lib/perl5/site_perl/5.8.5/DBIx/Class/Schema.pm line 149.
Use of uninitialized value in concatenation (.) or string at
/usr/lib/perl5/site_perl/5.8.5/DBIx/Class/Schema.pm line 150.
DBIx::Class::Schema::resultset(): Can't find source for  at ./test.pl
line 10
[hermida at dla2 test]$ 
 
 
Thank you for your help,
 
Leandro Hermida
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20061123/a1a6e718/attachment.htm


More information about the Dbix-class mailing list