[Catalyst] DBIC Create: Objects in DB?

Daniel Westermann-Clark daniel at acceleration.net
Sat Dec 31 21:31:14 CET 2005


On 2005-12-31 12:21:02 -0800, Dennis Daupert wrote:
>   But when I do a DBIx-Class insert, my db record looks like this:
>   
>   ,MyApp2=HASH(0x19970a0)->req->params->{fname},MyApp2=HASH(0x19970a0)->req->params->{lname},MyApp2=HASH(0x19970a0)->req->params->{username},MyApp2=HASH(0x19970a0)->req->params->{password},MyApp2=HASH(0x19970a0)->req->params->{email},1   
>   
>   # Populate the hash 
>   my %user = (   
>   fname    => "$c->req->params->{fname}",   
>   lname    => "$c->req->params->{lname}",   
>   username => "$c->req->params->{username}",   
>   password => "$c->req->params->{password}",   
>   email    => "$c->req->params->{email}",   
>   active   => '1'   ); 
>   
>   # Create the object 
>   my $new_user = MyApp2::Model::DBIC::Users->new(\%user); 
>   
>   # Insert the user 
>   $new_user->insert_or_update;  

Your variable interpolation is causing problems.  Try this instead:

$c->model('DBIC::Users')->create({
    fname    => $c->req->param('fname'),
    lname    => $c->req->param('lname'),
    username => $c->req->param('username'),
    password => $c->req->param('password'),
    email    => $c->req->param('email'),
    active   => 1,
});

Though you really should be doing some validation of those
parameters...

-- 
Daniel Westermann-Clark



More information about the Catalyst mailing list