[Dbix-class] how to select from two tables ?
Jason Kohles
email at jasonkohles.com
Sat Sep 15 16:52:38 GMT 2007
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 at jasonkohles.com
http://www.jasonkohles.com/
"A witty saying proves nothing." -- Voltaire
More information about the DBIx-Class
mailing list