in reply to Joins with Class::DBI
Check out the section on the has_many and has_a methods. You will want to add something like the following to your classes:
# To your authors class __PACKAGE__->has_many('books', 'My::DB::Books' => book_id); # To your books class __PACKAGE__->has_a('author_id', 'My::DB::Authors');
Then in your code you can use:
my $author = My::DB::Authors->retrieve($author_id); # method add_to_books is created for you by has_many $author->add_to_books({ col1 => value1, col2 => value2, ... }); # author_id will be filled in automatically my $books = $author->books; while (my $book = $books->next) { ... }
- Cees
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Joins with Class::DBI
by thpfft (Chaplain) on Jul 19, 2003 at 23:14 UTC |