[Dbix-class] Bug with find_or_new and insert_or_update with postgresql: any success?

Matt S Trout dbix-class at trout.me.uk
Sat Mar 8 16:34:05 GMT 2008


On Tue, Feb 26, 2008 at 12:56:21PM +0300, Alex Povolotsky wrote:
> Zbigniew Lukasiak wrote:
> >On Mon, Feb 25, 2008 at 9:53 PM, Alex Povolotsky <tarkhil at over.ru> wrote:
> >  
> >>Hello!
> >>
> >> I've found in archives nearly my case, that passing NULL to Pg is not
> >> 'not passing column at all', so adding a new row with a simple code like
> >> this
> >>
> >>  my $loc = $c->model($self->model_name)->find_or_new({lid => $id});
> >>  if ($form->submitted && $form->validate) {
> >>    # Fill in
> >> data
> >>
> >>    $loc->name($form->field('name'));
> >>    $loc->descr($form->field('descr'));
> >>    $loc->update_or_insert();
> >>    $c->req->redirect($c->uri_for('list'));
> >>  }
> >>
> >> is impossible.
> >>
> >> Maybe someone has found a good way to solve the problem, or at least a
> >> working workaround?
> >>    
> >
> >Just guessing - are you using HTML::FormFu?  HTML::FormFu::Model::DBIC
> >integrates FormFu with DBIC and works around this problem (by not
> >using find_or_new nor update_or_create). Personally I would be very
> >happy to see the debate on using the *_or_* methods for tables with Pg
> >serial primary keys reopened - but there are workarounds for it.
> >
> >
> >  
> I'm using FormBuilder.
> 
> I've made an UGLY workaround
> 
>    if (defined $loc->lid) {
>      $loc->name($form->field('name'));
>      $loc->descr($form->field('descr'));
>      $loc->update();
>    } else {
>      $c->model($self->model_name)->create({ map { $_ => 
> $form->field($_) } qw(name descr)});
>    }
> 
> But I hate it. Who can fix internal logic of DBIx::Class request builder?...

It doesn't need fixing.

See my reply to your original post for how to fix the bug in your code.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list