Jack Lauritsen wrote:
Hello,

I am building a (test only) site based modifying the classes in the
catalyst tutorial, and have a hopefully simple question. I have a search
box that takes an isbn number, and then build a book with the data from
amazon web services. The problem comes when I want to update the authors
list. I don't have the author id. How do I get the id out of
MyAppDB::Author? I tried the following:

==================================
foreach my $amazonauthor ($amazonbook->made_by())  {
    my $author = $c->model('MyAppDB::Author')->search({name =>
$amazonauthor});
'search' returns an array, so in scalar context this will put the array size into '$author' not what you want. Use either my ($author) = $c->model('MyAppDB::Author')->search({name => $amazonauthor});

or

my $author = $c->model('MyAppDB::Author')->search({name => $amazonauthor})->first;

    if ($author->{id} != undef) {
        $author =  $c->model('MyAppDB::Author')->search({name =>
$amazonauthor});
        $book->add_to_book_authors({author_id => $author->{id}});
    } else {
        $author = $c->model('MyAppDB::Author')->create({
        name  => $amazonauthor # yes, my DB has just \id name\
    });
    $book->add_to_book_authors({author_id => $author->{id}});
}
==================================
is the syntax wrong "$author->{id}"
I think this should be '$author->id'
or have I made the Author incorrectly?

thanks in advanced for anyone who can point me in the right direction.

Jack.



_______________________________________________
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/

Reply via email to