in reply to Re: Can't call method "find" on an undefined value
in thread Can't call method "find" on an undefined value

here is the code
package AddressBook::Controller::Address; use strict; use warnings; use base qw(Catalyst::Controller::FormBuilder Catalyst::Controller::Bi +ndLex); use Data::Dumper; sub edit : Local Form { my ($self, $c, $address_id, $person_id) = @_; my $address : Stashed; print $c->request->arguments->[0]; print "\n"; print Dumper(" address_id is: ".Dumper($address_id)); print Dumper("person_id is: ".Dumper($person_id)); my $persid = $c->model('AddressDB::Addresses')->find({person => $id}); my $person = $c->model('AddressDB::People')->find({id => $persid}); if ($self->formbuilder->submitted && $self->formbuilder->validate){ # transfer data from form to database $address->location($self->formbuilder->field('location')); $address->postal ($self->formbuilder->field('postal' )); $address->phone ($self->formbuilder->field('phone')); $address->email ($self->formbuilder->field('email')); $address->insert_or_update; $c->stash->{message} = ($address_id > 0 ? 'Updated ' : 'Added new ').'address for '. $ +address->person->name; $c->detach('list'); } else { # transfer data from database to form if(!$address_id){ $c->stash->{message} = 'Adding a new address '; } else { $c->stash->{message} = 'Updating an address '; } $c->stash->{message} .= ' for '. $address->person->name; $self->formbuilder->field(name => 'location', value => $address +->location); $self->formbuilder->field(name => 'postal', value => $address-> +postal); $self->formbuilder->field(name => 'phone', value => $address->p +hone); $self->formbuilder->field(name => 'email', value => $address->e +mail); } }
thanks

Replies are listed 'Best First'.
Re^3: Can't call method "find" on an undefined value
by Anonymous Monk on Jan 12, 2012 at 20:09 UTC
    the problem is in this line  my $persid = $c->model('AddressDB::Addresses')->find({person => $id});

      That line, or perhaps the next one. They both call a find method.

      Whichever line it is though, the problem is that the call to $c->model is returning undef.

        why is that? i don't get since $id has a value... my $id = $c->request->arguments->[0]*1; its like it's not seeing the value of $id
      i've tried to see what's in  c->model and came up with this error Use of uninitialized value $_[0] in join or string at /usr/local/share/perl/5.10.1/Catalyst/Log.pm line 88. and this is the line 88  my $message = join( "\n", @_ ); from fct
      sub _log { my $self = shift; my $level = shift; my $message = join( "\n", @_ ); $message .= "\n" unless $message =~ /\n$/; my $body = $self->_body; $body .= sprintf( "[%s] %s", $level, $message ); $self->_body($body); }
      any idea?