[Dbix-class] how to select from two tables ?

Silent silent2600 at gmail.com
Sat Sep 15 15:21:21 GMT 2007


Hi~
    I am new to dbix-class also SQL, in my test script I want to select from
two tables:

$ sqlite3 test.db
SQLite version 3.3.13
Enter ".help" for instructions
sqlite> .schema
CREATE TABLE author (
uid integer primary key,
uname text not null
);
CREATE TABLE news (
newsid integer primary key,
uid integer not null references author(uid),
title text not null,
body text not null
);


I want to get the news.title, news.body, and author.uname, but I can not
find out the method now.
###schema:
package My::Schema;
use base qw/DBIx::Class::Schema::Loader/;

__PACKAGE__->loader_options( relationships =3D> 1, debug =3D> 1,);
#ps: if relationships option is omited, "relationships" seems to be faulse,
but document say :"The default is to attempt the loading of relationships"
#__PACKAGE__->loader_options( relationships =3D> 1, );

1;


###test script:
$ cat test.pl
#!/usr/bin/perl
use lib ".";
use My::Schema;

my $dump =3D $ARGV[0] || undef;
my $schema =3D My::Schema->connect('dbi:SQLite:/home/hx/work/dbix/test.db');
#DBIx::Class::Schema::Loader->dump_to_dir('/tmp/z');

if ($dump) {
    my @news =3D $schema->resultset('News')->all(
        {
            join =3D> [qw / author /],
        }
      );
    for my $row (@news) {
        print $row->title,"\n", $row->uid, "\n", $row->body,"\n";   # how
can I get the author name here ?
    }

}


thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070915/971=
89196/attachment.htm


More information about the DBIx-Class mailing list