On Sep 15, 2007, at 10:21 AM, Silent wrote:

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

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
);

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


$row->uid->uname, although you probably want to rename the relationship so it makes more sense, by including

My::Schema::News->belongs_to( 'author', 'My::Schema::Author', 'uid' );

Then you can get it as;

$row->author->uname;

--
Jason Kohles
[EMAIL PROTECTED]
http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire



_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]

Reply via email to